102072024-03-29 13:47:35VargusA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 6/508ms5128 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];
    }
    if (a[1] != 1)
    {
        cout << "-1";
        return 0;
    }
    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;
        }
        if (maxi == b[j])
        {
            if (j < n)
                ++j;
            continue;
        }
        while (a[j] == i && maxi <= b[j] && maxi >= a[j])
        {
            ++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 (j > n)
                break;
        }
        if (j > n)
            break;
    }

    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 4
1 6
2 6
3 4
6 9
7 9
*/
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/03ms1812 KiB
2Wrong answer0/08ms2344 KiB
3Accepted1/13ms2264 KiB
4Accepted1/13ms2484 KiB
5Accepted2/22ms2592 KiB
6Accepted2/23ms2540 KiB
7Runtime error0/23ms2592 KiB
8Runtime error0/24ms2856 KiB
9Wrong answer0/24ms3032 KiB
10Wrong answer0/24ms3392 KiB
11Wrong answer0/24ms3624 KiB
12Runtime error0/26ms4000 KiB
13Runtime error0/23ms4016 KiB
14Wrong answer0/24ms4136 KiB
15Wrong answer0/24ms4140 KiB
16Wrong answer0/26ms4428 KiB
17Runtime error0/27ms4592 KiB
18Wrong answer0/28ms4596 KiB
19Runtime error0/28ms4544 KiB
20Wrong answer0/28ms4572 KiB
21Wrong answer0/28ms4740 KiB
22Wrong answer0/28ms4828 KiB
23Wrong answer0/28ms4804 KiB
24Wrong answer0/28ms4804 KiB
25Wrong answer0/28ms4804 KiB
26Wrong answer0/28ms4804 KiB
27Wrong answer0/28ms4888 KiB
28Wrong answer0/28ms5128 KiB