76422024-01-10 10:23:09CsongiA lehető legkevesebb átszállás (50 pont)cpp14Time limit exceeded 15/50301ms62768 KiB
#include <iostream>
#include <bits/stdc++.h>
#include <vector>

using namespace std;

pair<int, int> elerhetolncsucs(int v, vector<vector<int>> allomasok, vector<pair<int, int>> vonat)
{
    int legn = 0;
    int ind = 0;
    for (int i = 0; i < allomasok[v].size(); i++)
    {
        if (vonat[allomasok[v][i]].second > ind)
        {
            legn = allomasok[v][i];
            ind = vonat[allomasok[v][i]].second;
        }
    }
    pair<int, int> ki;
    ki.first = legn; //villamos 0-n
    ki.second = ind; //csucs 1-m
    return ki;
}

int main()
{
    int n, m;
    cin >> n >> m;
    //vector<int> vonatok(n);
    vector<pair<int, int>> vonat(n);
    vector<vector<int>> allomasok(m+1);
    bool egyes = false, utolso = false;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        //vonatok[i] = b - a + 1; //merete a vonatnak
        vonat[i].first = a;
        vonat[i].second = b;
        if (a == 1)
            egyes = true;
        if (b == m)
            utolso = true;
        //cout << a << " " << b << endl;
        for (int j = a; j <= b; j++)
        {
            allomasok[j].push_back(i);
        }
    }
    if (!egyes || !utolso)
    {
        cout << "-1";
    }
    else
    {
        int most = 1;
        vector<int> bejaras(0);
        while (most < m)
        {
            pair<int, int> itt = elerhetolncsucs(most, allomasok, vonat);
            most = itt.second;
            bejaras.push_back(itt.first);
            //cout << most << " " << itt.first;
        }
        cout << bejaras.size() - 1 << endl;
        for (int i = 0; i < bejaras.size(); i++)
        {
            cout << bejaras[i] + 1 << " ";
        }
    }   
}
SubtaskSumTestVerdictTimeMemory
base15/50
1Accepted0/03ms1940 KiB
2Time limit exceeded0/0301ms32720 KiB
3Accepted1/13ms2324 KiB
4Time limit exceeded0/1300ms10168 KiB
5Accepted2/23ms2708 KiB
6Accepted2/23ms2924 KiB
7Accepted2/218ms8796 KiB
8Accepted2/217ms11160 KiB
9Accepted2/228ms13700 KiB
10Accepted2/276ms19408 KiB
11Time limit exceeded0/2277ms15220 KiB
12Time limit exceeded0/2275ms18184 KiB
13Accepted2/2111ms11100 KiB
14Time limit exceeded0/2268ms10400 KiB
15Time limit exceeded0/2275ms13936 KiB
16Time limit exceeded0/2259ms18708 KiB
17Time limit exceeded0/2247ms26656 KiB
18Time limit exceeded0/2268ms28572 KiB
19Time limit exceeded0/2252ms30724 KiB
20Time limit exceeded0/2239ms32016 KiB
21Runtime error0/271ms62768 KiB
22Runtime error0/271ms62528 KiB
23Runtime error0/2108ms62292 KiB
24Runtime error0/2122ms62232 KiB
25Runtime error0/2151ms62104 KiB
26Runtime error0/2143ms61848 KiB
27Runtime error0/2155ms61844 KiB
28Runtime error0/2153ms61816 KiB