76942024-01-10 13:34:02adamA lehető legkevesebb átszállás (50 pont)cpp17Elfogadva 50/5012ms5784 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;

        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
base50/50
1Elfogadva0/03ms1828 KiB
2Elfogadva0/012ms3184 KiB
3Elfogadva1/13ms2332 KiB
4Elfogadva1/13ms2456 KiB
5Elfogadva2/23ms2804 KiB
6Elfogadva2/23ms2804 KiB
7Elfogadva2/23ms3200 KiB
8Elfogadva2/23ms3152 KiB
9Elfogadva2/23ms3296 KiB
10Elfogadva2/23ms3396 KiB
11Elfogadva2/24ms3636 KiB
12Elfogadva2/24ms3628 KiB
13Elfogadva2/23ms3392 KiB
14Elfogadva2/24ms3588 KiB
15Elfogadva2/24ms3808 KiB
16Elfogadva2/24ms3928 KiB
17Elfogadva2/28ms4800 KiB
18Elfogadva2/28ms4984 KiB
19Elfogadva2/29ms5136 KiB
20Elfogadva2/210ms5264 KiB
21Elfogadva2/212ms5412 KiB
22Elfogadva2/212ms5472 KiB
23Elfogadva2/24ms5484 KiB
24Elfogadva2/24ms5504 KiB
25Elfogadva2/24ms5644 KiB
26Elfogadva2/24ms5772 KiB
27Elfogadva2/24ms5784 KiB
28Elfogadva2/24ms5676 KiB