76412024-01-10 10:21:19CsongiA lehető legkevesebb átszállás (50 pont)cpp14Time limit exceeded 15/50301ms62608 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";
        exit(0);
    }
    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/03ms1812 KiB
2Time limit exceeded0/0301ms32596 KiB
3Accepted1/13ms2308 KiB
4Time limit exceeded0/1300ms10132 KiB
5Accepted2/23ms2516 KiB
6Accepted2/23ms2640 KiB
7Accepted2/218ms8324 KiB
8Accepted2/217ms10812 KiB
9Accepted2/228ms13396 KiB
10Accepted2/276ms18940 KiB
11Time limit exceeded0/2268ms14780 KiB
12Time limit exceeded0/2247ms17992 KiB
13Accepted2/2108ms10944 KiB
14Time limit exceeded0/2244ms10516 KiB
15Time limit exceeded0/2275ms13844 KiB
16Time limit exceeded0/2275ms18572 KiB
17Time limit exceeded0/2268ms26724 KiB
18Time limit exceeded0/2256ms28656 KiB
19Time limit exceeded0/2268ms30828 KiB
20Time limit exceeded0/2264ms32224 KiB
21Runtime error0/272ms62608 KiB
22Runtime error0/271ms62372 KiB
23Runtime error0/2123ms62340 KiB
24Runtime error0/2118ms62316 KiB
25Runtime error0/2137ms62292 KiB
26Runtime error0/2181ms62288 KiB
27Runtime error0/2156ms62280 KiB
28Runtime error0/2151ms62232 KiB