75302024-01-09 13:30:08gyjazminA lehető legkevesebb átszállás (50 pont)cpp17Accepted 50/5010ms5536 KiB


#include <iostream>
#include <vector>
using namespace std;
vector<int> v(1);
vector<vector<int>> graf;
int cv = 0;
bool kovetk() {
    v.push_back(0);
    int eleje= cv;
    int s = v.size()-1;
    int i = v[s-1]+1;
    int maxv=cv;
    while (i <= graf.size() - 1&& graf[i][0] <= cv) {
        if (graf[i][1] > maxv) {
            maxv = graf[i][1];
            v[s] = i;
        }        
        i++;
    }
    cv = maxv;
    if (eleje == cv) {
        return false;
    }
    else {
        return true;
    }

}
int main()
{
    int n,m;
    cin >> n>>m;
    graf.resize(n+1);    
    for (int i = 0;i < n;i++) {
        int egyik, masik;
        cin >> egyik >> masik;
        graf[i].resize(2);
        graf[i + 1].push_back(egyik);
        graf[i + 1].push_back(masik);
        if (egyik == 1&& masik >cv) {
            cv = masik;
            v[0] = i + 1;
        }
    }
    if (cv == 0) {
        cout << -1 << endl;
    }
    else {
        bool eljut=true;
        while (cv != m) {
            eljut = kovetk();
            if (!eljut) {
                cout << -1 << endl;
                break;
            }
        }
        if (eljut) {
            cout << v.size() - 1 << endl;
            for (int i = 0;i < v.size();i++) {
                cout << v[i] << " ";
            }
            cout << endl;
        }
    }

    
}

SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1872 KiB
2Accepted0/010ms3024 KiB
3Accepted1/13ms2288 KiB
4Accepted1/13ms2496 KiB
5Accepted2/23ms2572 KiB
6Accepted2/23ms2720 KiB
7Accepted2/23ms3120 KiB
8Accepted2/24ms3360 KiB
9Accepted2/24ms3488 KiB
10Accepted2/24ms3620 KiB
11Accepted2/26ms3936 KiB
12Accepted2/27ms4072 KiB
13Accepted2/23ms3956 KiB
14Accepted2/24ms4220 KiB
15Accepted2/24ms4356 KiB
16Accepted2/27ms4492 KiB
17Accepted2/28ms4896 KiB
18Accepted2/28ms4984 KiB
19Accepted2/29ms4980 KiB
20Accepted2/29ms5008 KiB
21Accepted2/210ms5204 KiB
22Accepted2/210ms5180 KiB
23Accepted2/29ms5184 KiB
24Accepted2/29ms5324 KiB
25Accepted2/29ms5284 KiB
26Accepted2/29ms5344 KiB
27Accepted2/210ms5536 KiB
28Accepted2/210ms5496 KiB