76822024-01-10 12:52:34adamA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 36/50300ms5144 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;
        for (int j = 0; j < (train_stops.second - train_stops.first); j++) {
            stations[train_stops.first + j]++;
        }

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

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



}
SubtaskSumTestVerdictTimeMemory
base36/50
1Accepted0/03ms1824 KiB
2Accepted0/014ms3196 KiB
3Accepted1/13ms2228 KiB
4Accepted1/13ms2320 KiB
5Accepted2/23ms2536 KiB
6Wrong answer0/23ms2524 KiB
7Accepted2/23ms2928 KiB
8Accepted2/23ms3152 KiB
9Accepted2/23ms3376 KiB
10Accepted2/24ms3532 KiB
11Accepted2/24ms3700 KiB
12Accepted2/26ms3992 KiB
13Accepted2/23ms3552 KiB
14Accepted2/24ms3632 KiB
15Accepted2/24ms3900 KiB
16Accepted2/26ms4296 KiB
17Accepted2/28ms4792 KiB
18Accepted2/210ms4728 KiB
19Accepted2/210ms4892 KiB
20Accepted2/212ms5124 KiB
21Accepted2/213ms5144 KiB
22Accepted2/213ms5056 KiB
23Time limit exceeded0/2300ms3604 KiB
24Time limit exceeded0/2252ms3848 KiB
25Time limit exceeded0/2254ms4124 KiB
26Time limit exceeded0/2270ms4264 KiB
27Time limit exceeded0/2273ms4244 KiB
28Time limit exceeded0/2282ms3960 KiB