76932024-01-10 13:31:00adamA lehető legkevesebb átszállás (50 pont)cpp17Hibás válasz 40/5010ms5408 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;

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

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



}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/50
1Elfogadva0/03ms1824 KiB
2Elfogadva0/010ms3224 KiB
3Elfogadva1/13ms2372 KiB
4Elfogadva1/13ms2696 KiB
5Elfogadva2/23ms2948 KiB
6Hibás válasz0/23ms3124 KiB
7Elfogadva2/23ms3160 KiB
8Elfogadva2/23ms3360 KiB
9Elfogadva2/23ms3504 KiB
10Elfogadva2/23ms3524 KiB
11Elfogadva2/24ms3624 KiB
12Elfogadva2/24ms3888 KiB
13Elfogadva2/23ms3856 KiB
14Elfogadva2/23ms3884 KiB
15Elfogadva2/24ms4044 KiB
16Elfogadva2/24ms4160 KiB
17Elfogadva2/28ms4608 KiB
18Elfogadva2/28ms4828 KiB
19Elfogadva2/29ms4932 KiB
20Elfogadva2/29ms4964 KiB
21Elfogadva2/210ms5236 KiB
22Elfogadva2/210ms5192 KiB
23Hibás válasz0/24ms5208 KiB
24Hibás válasz0/24ms5200 KiB
25Elfogadva2/24ms5368 KiB
26Hibás válasz0/24ms5388 KiB
27Hibás válasz0/24ms5404 KiB
28Elfogadva2/24ms5408 KiB