115192024-10-17 11:52:10madvirA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 2/50300ms1104 KiB
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

struct jarat {
    int k,v,s;
};

int rule(jarat x, jarat y) {
    if(x.s<y.s) {
        if(x.v>=y.v) return 1;
        else return 0;
    }
    else return 0;
};

int main()
{
    int n,m;
    cin >>n >> m;
    jarat a[n]={0};
    set<int> index;
    int ke[n], ve[n];
    cin >>ke[0] >> ve[0];
    for(int i=1; i<n; i++) {
        cin >> ke[i] >> ve[i];
    }
    int f=1, ind=0, maxf;

    a[0].k=ke[0];
    a[0].v=ve[0];
    int sor=1;
    while(f<n) {
        if(ke[f]==ke[f-1]) {
            maxf=f;
            while(ke[f]==ke[f-1]) {
                if(ve[f]>ve[f-1]) {
                    maxf=f;
                }
                sor++;
                f++;
            }
            sor--;
            a[ind].k=ke[maxf];
            a[ind].v=ve[maxf];
            a[ind].s=sor;
            ind++;
        }
        else{
            a[ind].k=ke[f];
            a[ind].v=ve[f];
            a[ind].s=sor;
            sor++;
            f++;
            ind++;
        }
    }
    f--;

    int let[m+1]={0}, lehet=0;
    for(int i=0; i<f; i++) {
        for(int w=a[i].k; w<=a[i].v; w++) {
            let[w]++;
        }
    }

    lehet=0;
    for(int i=1; i<=m && lehet==0; i++) {
        if(let[i]==0) lehet=-1;
    }

    if(lehet==0) {
        int x=a[0].v;
        for(int i=1; i<f; i++) {
            if(x<=a[i].v && a[i].k<=x) {
                x=a[i].v;
                index.insert(a[i].s);
            }
        }
        cout << index.size()-1 << endl;
        set<int>::iterator ptr;
        for(ptr=index.begin(); ptr!=index.end(); ptr++) {
            cout<< *ptr << " ";
        }
    }
    else {
        cout << -1;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Wrong answer0/01ms328 KiB
2Wrong answer0/09ms1092 KiB
3Accepted1/11ms508 KiB
4Accepted1/11ms328 KiB
5Wrong answer0/21ms512 KiB
6Wrong answer0/21ms328 KiB
7Wrong answer0/22ms328 KiB
8Wrong answer0/22ms332 KiB
9Wrong answer0/23ms328 KiB
10Wrong answer0/24ms576 KiB
11Wrong answer0/24ms524 KiB
12Wrong answer0/24ms532 KiB
13Wrong answer0/22ms416 KiB
14Wrong answer0/23ms420 KiB
15Wrong answer0/24ms668 KiB
16Wrong answer0/24ms568 KiB
17Wrong answer0/27ms968 KiB
18Wrong answer0/28ms896 KiB
19Wrong answer0/28ms1104 KiB
20Wrong answer0/28ms1088 KiB
21Wrong answer0/29ms956 KiB
22Wrong answer0/29ms1100 KiB
23Time limit exceeded0/2298ms964 KiB
24Time limit exceeded0/2298ms832 KiB
25Time limit exceeded0/2300ms960 KiB
26Time limit exceeded0/2300ms824 KiB
27Time limit exceeded0/2280ms1084 KiB
28Time limit exceeded0/2282ms912 KiB