76582024-01-10 10:54:15CsongiA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 20/50181ms62680 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);

    int n, m;
    cin >> n >> m;
    
    vector<pair<int, int>> vonatok(n);
    vector<vector<int>> allomasok(m+1);
    
    bool elso = false, utolso = false;
    
    for (int i = 0; i < n; i++)
    {
        int kezdo, veg;
        cin >> kezdo >> veg;
        vonatok[i] = {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";
                return 0;
            }

            jelenlegi = ujIndex;
            bejaras.push_back(legujabb);
        }
        
        cout << bejaras.size() - 1 << '\n';

        if (bejaras.size() > 1) {
            for (int i = 0; i < bejaras.size() - 1; i++)
            {
                cout << bejaras[i] + 1 << ' ';
            }
        }
    }   
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Wrong answer0/03ms1828 KiB
2Wrong answer0/059ms36796 KiB
3Accepted1/13ms2416 KiB
4Accepted1/13ms2288 KiB
5Partially correct1/23ms2508 KiB
6Partially correct1/23ms2608 KiB
7Partially correct1/27ms6244 KiB
8Partially correct1/28ms7684 KiB
9Partially correct1/29ms8712 KiB
10Partially correct1/214ms11928 KiB
11Partially correct1/223ms17336 KiB
12Partially correct1/227ms21188 KiB
13Partially correct1/29ms7624 KiB
14Partially correct1/217ms12188 KiB
15Partially correct1/224ms16364 KiB
16Partially correct1/229ms21372 KiB
17Partially correct1/246ms30816 KiB
18Partially correct1/248ms32596 KiB
19Partially correct1/250ms35200 KiB
20Partially correct1/252ms36756 KiB
21Partially correct1/254ms38552 KiB
22Partially correct1/254ms38840 KiB
23Runtime error0/2107ms62680 KiB
24Runtime error0/2123ms62680 KiB
25Runtime error0/2150ms62444 KiB
26Runtime error0/2167ms62416 KiB
27Runtime error0/2181ms62356 KiB
28Runtime error0/2151ms62160 KiB