77442024-01-10 21:53:52CsongiA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 6/50189ms63416 KiB
#include <iostream>
#include <vector>

using namespace std;

pair<int, int> elerheto_csucs(int v, const vector<vector<int>>& allomasok, const vector<pair<int, int>>& vonatok)
{
    int legujabb = 0, index = 0;

    for (int i : allomasok[v])
    {
        if (vonatok[i].second > index)
        {
            legujabb = i;
            index = vonatok[i].second;
        }
    }

    return { legujabb, index };
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector<pair<int, int>> vonatok;
    vector<vector<int>> allomasok(m + 1);

    bool elso = false, utolso = false;

    int prev_veg = -1;

    for (int i = 0; i < n; i++)
    {
        int kezdo, veg;
        cin >> kezdo >> veg;
        if (i != 0 && vonatok.back().first == kezdo && vonatok.back().second > veg)
        {

        }
        else
        {
            vonatok.push_back({ kezdo, veg });

            if (kezdo == 1)
                elso = true;
            if (veg == m)
                utolso = true;

            for (int j = kezdo; j <= veg; j++)
            {
                allomasok[j].push_back(i);
            }
        }
        
    }

    if (!elso || !utolso)
    {
        cout << "-1";
    }
    else
    {
        int jelenlegi = 1;
        vector<int> bejaras;

        while (jelenlegi < m)
        {
            auto [legujabb, ujIndex] = elerheto_csucs(jelenlegi, allomasok, vonatok);
            if (ujIndex <= jelenlegi) {
                cout << "-1";  // vegtelen loop?
                return 0;
            }
            jelenlegi = ujIndex;
            bejaras.push_back(legujabb);
        }

        cout << bejaras.size() - 1 << '\n';

        for (int i : bejaras)
        {
            cout << i + 1 << ' ';
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/03ms1824 KiB
2Wrong answer0/057ms36268 KiB
3Accepted1/13ms2316 KiB
4Accepted1/13ms2392 KiB
5Accepted2/23ms2448 KiB
6Accepted2/23ms2516 KiB
7Wrong answer0/27ms5952 KiB
8Wrong answer0/28ms7044 KiB
9Wrong answer0/29ms8300 KiB
10Wrong answer0/214ms11700 KiB
11Wrong answer0/224ms16464 KiB
12Wrong answer0/228ms20020 KiB
13Wrong answer0/29ms7136 KiB
14Wrong answer0/217ms11528 KiB
15Wrong answer0/223ms15628 KiB
16Wrong answer0/230ms20420 KiB
17Wrong answer0/246ms29616 KiB
18Wrong answer0/248ms31648 KiB
19Wrong answer0/252ms33988 KiB
20Wrong answer0/254ms35416 KiB
21Wrong answer0/257ms37104 KiB
22Wrong answer0/257ms37500 KiB
23Runtime error0/2123ms63416 KiB
24Runtime error0/2145ms63404 KiB
25Runtime error0/2165ms63388 KiB
26Runtime error0/2175ms63356 KiB
27Runtime error0/2187ms63332 KiB
28Runtime error0/2189ms63312 KiB