75242024-01-09 13:26:24gyjazminA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 46/5010ms5388 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++;
    }
    if (i == graf.size() - 1) {
        v.erase(v.begin() + s);
    }
    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
base46/50
1Wrong answer0/03ms1880 KiB
2Accepted0/010ms3068 KiB
3Accepted1/13ms2444 KiB
4Accepted1/13ms2676 KiB
5Accepted2/23ms2808 KiB
6Wrong answer0/23ms3024 KiB
7Accepted2/23ms3288 KiB
8Accepted2/24ms3548 KiB
9Accepted2/24ms3664 KiB
10Accepted2/24ms4036 KiB
11Accepted2/26ms4048 KiB
12Wrong answer0/27ms4372 KiB
13Accepted2/24ms4212 KiB
14Accepted2/24ms4440 KiB
15Accepted2/24ms4528 KiB
16Accepted2/27ms4812 KiB
17Accepted2/28ms4836 KiB
18Accepted2/28ms4916 KiB
19Accepted2/28ms5168 KiB
20Accepted2/29ms5060 KiB
21Accepted2/29ms5056 KiB
22Accepted2/29ms5056 KiB
23Accepted2/29ms5204 KiB
24Accepted2/29ms5184 KiB
25Accepted2/29ms5068 KiB
26Accepted2/29ms5388 KiB
27Accepted2/29ms5348 KiB
28Accepted2/29ms5280 KiB