69342023-12-20 18:27:13MagyarKendeSZLGA lehető legkevesebb átszállás (50 pont)cpp17Runtime error 1/5012ms4836 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
using namespace std;
const int INF = 1e9;

using train = array<int, 3>; // dist, pos, id

int main() {
    int N, M;
    cin >> N >> M;

    vector<train> TS(N);

    int i = 0;
    for (train& tr : TS) {
        cin >> tr[1] >> tr[0];
        tr[0] -= tr[1];
        tr[2] = ++i;
    }

    priority_queue<train> pq;
    vector<int> path;
    vector<bool> bitmask(M + 1);

    for (int pos = 0, i = 0; !bitmask[M]; i++) {
        pq.push(TS[i]);
        if (pos < TS[i][1]) {
            const train& t = pq.top();
            int i;
            for (i = t[1]; i <= M && i <= t[1] + t[0]; i++) {
                bitmask[i] = 1;
            }
            
            pos = i - 1;
/*
            cout << t[2] << ' ' << t[1] << ' ' << t[0] << " | ";
            for (int i = 1; i <= M; i++) cout << bitmask[i] << ' ';
            cout << '\n';
*/
            path.push_back(t[2]);
            pq.pop();
        }
    }

    cout << path.size() - 1 << '\n';
    for (int n : path)  {
        cout << n << ' ';
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base1/50
1Accepted0/03ms1812 KiB
2Runtime error0/012ms2944 KiB
3Wrong answer0/13ms2212 KiB
4Wrong answer0/13ms2428 KiB
5Wrong answer0/23ms2512 KiB
6Wrong answer0/23ms2536 KiB
7Wrong answer0/23ms2660 KiB
8Runtime error0/24ms3032 KiB
9Wrong answer0/24ms3460 KiB
10Wrong answer0/24ms3292 KiB
11Runtime error0/26ms3528 KiB
12Wrong answer0/27ms3768 KiB
13Runtime error0/24ms3704 KiB
14Wrong answer0/24ms3552 KiB
15Wrong answer0/24ms3852 KiB
16Wrong answer0/27ms3992 KiB
17Runtime error0/28ms4288 KiB
18Wrong answer0/29ms4160 KiB
19Wrong answer0/29ms4372 KiB
20Wrong answer0/29ms4376 KiB
21Wrong answer0/210ms4384 KiB
22Wrong answer0/210ms4392 KiB
23Partially correct1/29ms4636 KiB
24Runtime error0/29ms4808 KiB
25Wrong answer0/29ms4692 KiB
26Runtime error0/29ms4836 KiB
27Runtime error0/29ms4704 KiB
28Wrong answer0/29ms4604 KiB