76932024-01-10 13:31:00adamA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 40/5010ms5408 KiB
#include <bits/stdc++.h>
using namespace std;

pair<int, int> get_longest (pair<int, int> from, vector<pair<int, int>> trains) {
    pair<int, int> highest;
    for (int i = 0; i < trains.size(); i++) {
        if (trains[i].first - 1 <= from.second && trains[i].second <= trains[i].second)
            if (trains[i].second > highest.second)
                highest = pair(i, trains[i].second - 1);
    }
    return highest;

}

int main() {
    cin.tie(nullptr );
    ios_base::sync_with_stdio(false);
    int train_count = 0;
    int station_count = 0;
    cin >> train_count >> station_count;
    vector<pair<int, int>> trains(train_count, pair(0, 0));
    vector<int> stations(station_count, 0);


    for (int i = 0; i < train_count -1; i++) {
        pair<int, int> train_stops;
        cin >> train_stops.first >> train_stops.second;

        trains[i] = train_stops;
    }
    int boardings = -1;
    vector<int> boarded_trains(0, 0);
    pair<int, int> current_station (0, 0);
    while (current_station.second != station_count - 1) {
        pair<int, int> last = current_station;
        boardings++;
        current_station = get_longest(current_station, trains);
        boarded_trains.push_back(current_station.first);
        if (current_station.second == last.second && boardings > -1) {
            cout << -1 << endl;
            return 0;
        }

    }
    cout << boardings << endl;
    for (int train : boarded_trains) {
        cout << train + 1 << " ";
    }
    cout << endl;



}
SubtaskSumTestVerdictTimeMemory
base40/50
1Accepted0/03ms1824 KiB
2Accepted0/010ms3224 KiB
3Accepted1/13ms2372 KiB
4Accepted1/13ms2696 KiB
5Accepted2/23ms2948 KiB
6Wrong answer0/23ms3124 KiB
7Accepted2/23ms3160 KiB
8Accepted2/23ms3360 KiB
9Accepted2/23ms3504 KiB
10Accepted2/23ms3524 KiB
11Accepted2/24ms3624 KiB
12Accepted2/24ms3888 KiB
13Accepted2/23ms3856 KiB
14Accepted2/23ms3884 KiB
15Accepted2/24ms4044 KiB
16Accepted2/24ms4160 KiB
17Accepted2/28ms4608 KiB
18Accepted2/28ms4828 KiB
19Accepted2/29ms4932 KiB
20Accepted2/29ms4964 KiB
21Accepted2/210ms5236 KiB
22Accepted2/210ms5192 KiB
23Wrong answer0/24ms5208 KiB
24Wrong answer0/24ms5200 KiB
25Accepted2/24ms5368 KiB
26Wrong answer0/24ms5388 KiB
27Wrong answer0/24ms5404 KiB
28Accepted2/24ms5408 KiB