76882024-01-10 13:15:05adamA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 2/50300ms4752 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) {
        if (stations[current_station.second] == 0) {
            cout << -1 << endl;
            return 0;
        }
        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
base2/50
1Wrong answer0/03ms1828 KiB
2Wrong answer0/07ms2872 KiB
3Accepted1/13ms2272 KiB
4Accepted1/13ms2480 KiB
5Wrong answer0/23ms2688 KiB
6Wrong answer0/23ms2924 KiB
7Wrong answer0/23ms3148 KiB
8Wrong answer0/23ms3100 KiB
9Wrong answer0/23ms3296 KiB
10Wrong answer0/24ms3344 KiB
11Wrong answer0/24ms3428 KiB
12Wrong answer0/24ms3336 KiB
13Wrong answer0/23ms3276 KiB
14Wrong answer0/24ms3612 KiB
15Wrong answer0/24ms3840 KiB
16Wrong answer0/24ms3976 KiB
17Wrong answer0/26ms4456 KiB
18Wrong answer0/26ms4436 KiB
19Wrong answer0/27ms4632 KiB
20Wrong answer0/26ms4496 KiB
21Wrong answer0/27ms4492 KiB
22Wrong answer0/27ms4752 KiB
23Time limit exceeded0/2300ms3664 KiB
24Time limit exceeded0/2270ms3604 KiB
25Time limit exceeded0/2270ms4008 KiB
26Time limit exceeded0/2266ms4024 KiB
27Time limit exceeded0/2261ms3912 KiB
28Time limit exceeded0/2238ms4036 KiB