76792024-01-10 12:41:34adamElágazás nélküli úton levő települések (50 pont)cpp17Time limit exceeded 0/50300ms64872 KiB
#include <bits/stdc++.h>
using namespace std;

pair<int, int> get_longest (pair<int, int> from, vector<pair<int, int>> trains, vector<vector<int>> stations) {
    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() {
    int train_count = 0;
    int station_count = 0;
    cin >> train_count >> station_count;
    vector<pair<int, int>> trains(train_count, pair(0, 0));
    vector<vector<int>> stations(station_count, vector(0, 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 - 1 + j].push_back(i);
        }

        trains[i] = train_stops;
    }
    int boardings = -1;
    if (stations[station_count-1].empty() == 0) {
        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, stations);
        boarded_trains.push_back(current_station.first);

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



}
SubtaskSumTestVerdictTimeMemory
base0/50
1Time limit exceeded0/0256ms5576 KiB
2Runtime error0/078ms64872 KiB
3Wrong answer0/23ms2204 KiB
4Time limit exceeded0/2300ms18224 KiB
5Wrong answer0/23ms2676 KiB
6Wrong answer0/23ms2736 KiB
7Time limit exceeded0/2250ms4376 KiB
8Time limit exceeded0/2261ms6444 KiB
9Time limit exceeded0/2263ms19184 KiB
10Runtime error0/259ms64072 KiB
11Runtime error0/271ms64040 KiB
12Runtime error0/271ms63808 KiB
13Time limit exceeded0/3261ms6880 KiB
14Time limit exceeded0/3266ms18992 KiB
15Runtime error0/363ms63408 KiB
16Runtime error0/371ms63168 KiB
17Runtime error0/368ms63136 KiB
18Runtime error0/381ms62908 KiB
19Runtime error0/372ms62900 KiB
20Runtime error0/382ms62636 KiB
21Runtime error0/374ms62632 KiB
22Runtime error0/371ms62632 KiB