101412024-03-28 15:15:37VargusA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 6/508ms5724 KiB
#include <iostream>
#include <queue>
#include <algorithm>
#define ll long long

using namespace std;

int main()
{
    ll n, m;
    cin >> n >> m;
    vector <ll> a(n + 1), b(n + 1);
    for (ll i = 1; i <= n; ++i)
    {
        cin >> a[i] >> b[i];
    }
    ll j = 1;
    deque <ll> res(1), poz;
    res[0] = 0;
    ll maxi = 1, db;
    b[0] = 999999;
    for (ll i = 1; i <= m; ++i)
    {
        db = 0;
        if (maxi > b[j])
        {
            ++j;
            continue;
        }
        while (a[j] == i && maxi <= b[j] && maxi >= a[j])
        {
            if (maxi == b[j])
            {
                break;
            }
            ++db;
            poz.push_front(j);
            res.push_front(b[j]);
            if (res.front() <= b[j])
            {
                if (maxi < b[j])
                    maxi = b[j];
            }
            if (maxi > b[j - 1] && db > 1)
            {
                poz.erase(poz.begin() + j - 1);
                res.erase(res.begin() + j - 1);
            }
            ++j;
        }

    }

    if (res.front() == m)
    {
        cout << poz.size() - 1 << endl;
        for (ll i = poz.size() - 1; i >= 0; --i)
        {
            cout << poz[i] << " ";
        }
    }
    else
        cout << "-1";

    return 0;
}
/*
6 9
1 2
1 4
2 6
3 4
4 5
7 9
*/
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/03ms1816 KiB
2Wrong answer0/08ms2440 KiB
3Accepted1/13ms2500 KiB
4Accepted1/13ms2576 KiB
5Accepted2/23ms2816 KiB
6Accepted2/23ms2836 KiB
7Runtime error0/23ms3028 KiB
8Runtime error0/24ms3168 KiB
9Wrong answer0/24ms3188 KiB
10Wrong answer0/24ms3480 KiB
11Wrong answer0/24ms3732 KiB
12Runtime error0/26ms3996 KiB
13Runtime error0/23ms3992 KiB
14Wrong answer0/24ms3772 KiB
15Wrong answer0/24ms3880 KiB
16Wrong answer0/26ms4336 KiB
17Wrong answer0/27ms4420 KiB
18Wrong answer0/28ms4540 KiB
19Runtime error0/28ms4684 KiB
20Wrong answer0/28ms4720 KiB
21Wrong answer0/28ms4940 KiB
22Wrong answer0/28ms5060 KiB
23Wrong answer0/28ms5172 KiB
24Wrong answer0/28ms5280 KiB
25Wrong answer0/28ms5392 KiB
26Wrong answer0/28ms5504 KiB
27Wrong answer0/28ms5616 KiB
28Wrong answer0/28ms5724 KiB