76802024-01-10 12:43:32adamA lehető legkevesebb átszállás (50 pont)cpp17Time limit exceeded 12/50300ms63464 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
base12/50
1Accepted0/03ms1808 KiB
2Time limit exceeded0/0259ms32376 KiB
3Time limit exceeded0/1261ms5844 KiB
4Time limit exceeded0/1261ms10144 KiB
5Accepted2/23ms2804 KiB
6Time limit exceeded0/2300ms10352 KiB
7Accepted2/217ms8536 KiB
8Accepted2/217ms10716 KiB
9Accepted2/227ms13144 KiB
10Accepted2/274ms18824 KiB
11Time limit exceeded0/2272ms14568 KiB
12Time limit exceeded0/2282ms17600 KiB
13Accepted2/2105ms10592 KiB
14Time limit exceeded0/2263ms9972 KiB
15Time limit exceeded0/2270ms13364 KiB
16Time limit exceeded0/2257ms17888 KiB
17Time limit exceeded0/2246ms25952 KiB
18Time limit exceeded0/2263ms27816 KiB
19Time limit exceeded0/2270ms30268 KiB
20Time limit exceeded0/2238ms31456 KiB
21Runtime error0/272ms63464 KiB
22Runtime error0/271ms63448 KiB
23Runtime error0/2101ms63424 KiB
24Runtime error0/2116ms63392 KiB
25Runtime error0/2126ms63352 KiB
26Runtime error0/2135ms63352 KiB
27Runtime error0/2143ms63320 KiB
28Runtime error0/2143ms63316 KiB