76942024-01-10 13:34:02adamA lehető legkevesebb átszállás (50 pont)cpp17Accepted 50/5012ms5784 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; 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
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/012ms3184 KiB
3Accepted1/13ms2332 KiB
4Accepted1/13ms2456 KiB
5Accepted2/23ms2804 KiB
6Accepted2/23ms2804 KiB
7Accepted2/23ms3200 KiB
8Accepted2/23ms3152 KiB
9Accepted2/23ms3296 KiB
10Accepted2/23ms3396 KiB
11Accepted2/24ms3636 KiB
12Accepted2/24ms3628 KiB
13Accepted2/23ms3392 KiB
14Accepted2/24ms3588 KiB
15Accepted2/24ms3808 KiB
16Accepted2/24ms3928 KiB
17Accepted2/28ms4800 KiB
18Accepted2/28ms4984 KiB
19Accepted2/29ms5136 KiB
20Accepted2/210ms5264 KiB
21Accepted2/212ms5412 KiB
22Accepted2/212ms5472 KiB
23Accepted2/24ms5484 KiB
24Accepted2/24ms5504 KiB
25Accepted2/24ms5644 KiB
26Accepted2/24ms5772 KiB
27Accepted2/24ms5784 KiB
28Accepted2/24ms5676 KiB