76862024-01-10 13:11:14adamA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 2/50268ms4844 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;
        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/03ms1832 KiB
2Wrong answer0/07ms2872 KiB
3Accepted1/13ms2260 KiB
4Accepted1/13ms2476 KiB
5Wrong answer0/23ms2688 KiB
6Wrong answer0/23ms2772 KiB
7Wrong answer0/23ms2804 KiB
8Wrong answer0/23ms2812 KiB
9Wrong answer0/23ms2788 KiB
10Wrong answer0/24ms3088 KiB
11Wrong answer0/24ms3464 KiB
12Wrong answer0/24ms3632 KiB
13Wrong answer0/23ms3400 KiB
14Wrong answer0/24ms3756 KiB
15Wrong answer0/24ms3940 KiB
16Wrong answer0/24ms4200 KiB
17Wrong answer0/24ms4628 KiB
18Wrong answer0/26ms4716 KiB
19Wrong answer0/26ms4656 KiB
20Wrong answer0/26ms4656 KiB
21Wrong answer0/27ms4584 KiB
22Wrong answer0/27ms4844 KiB
23Time limit exceeded0/2259ms3816 KiB
24Time limit exceeded0/2268ms3944 KiB
25Time limit exceeded0/2268ms4108 KiB
26Time limit exceeded0/2248ms4088 KiB
27Time limit exceeded0/2264ms4064 KiB
28Time limit exceeded0/2264ms4104 KiB