76242024-01-10 09:22:29AGergoA lehető legkevesebb átszállás (50 pont)cpp17Runtime error 42/508ms4348 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
//cin.tie(0);
//iostream::sync_with_stdio(0);
bool hasStart=false,hasEnd=false;
int vonatszam, allomasszam, current = 1, maxLength, maxID, id=0,num=-1;

cin >> vonatszam >> allomasszam;

vector<int> vonatStart(vonatszam);
vector<int> vonatEnd(vonatszam);
vector<int> valasz;

for(int i = 0; i< vonatszam; i++)
{
    cin >> vonatStart[i] >> vonatEnd[i];
    if(vonatStart[i] == 1)
    {
        hasStart = true;
    }

    if(vonatEnd[i] == allomasszam)
    {
        hasEnd = true;
    }
}
if(hasStart == false || hasEnd == false)
{
    cout << "-1";
}
else
{
    while(current != allomasszam)
    {

        if(vonatStart[id] <= current && vonatEnd[id]>maxLength)
        {
            maxID = id;
            maxLength = vonatEnd[id];
        }
        else if (vonatStart[id] > current)
        {
            if(maxLength == current)
            {
                cout << "-1";
                hasEnd = false;
                break;

            }
        num++;
        current = maxLength;
        valasz.push_back(maxID);
        id--;
        }
        id++;
    }
    if(hasEnd == true)
    {
        cout << num <<"\n";

        for(int asd:valasz)
        {
            cout << asd+1 << " ";
        }
    }
}


}
SubtaskSumTestVerdictTimeMemory
base42/50
1Accepted0/03ms1940 KiB
2Accepted0/08ms2252 KiB
3Accepted1/13ms2608 KiB
4Accepted1/13ms2520 KiB
5Accepted2/23ms2720 KiB
6Accepted2/23ms2952 KiB
7Accepted2/23ms3024 KiB
8Accepted2/23ms3112 KiB
9Accepted2/24ms3112 KiB
10Accepted2/24ms3356 KiB
11Accepted2/24ms3268 KiB
12Accepted2/26ms3540 KiB
13Accepted2/23ms3452 KiB
14Accepted2/24ms3560 KiB
15Accepted2/24ms3568 KiB
16Accepted2/26ms3476 KiB
17Accepted2/27ms3756 KiB
18Accepted2/28ms3812 KiB
19Accepted2/28ms4008 KiB
20Accepted2/28ms3964 KiB
21Accepted2/28ms4272 KiB
22Accepted2/28ms4216 KiB
23Runtime error0/28ms4328 KiB
24Runtime error0/28ms4308 KiB
25Accepted2/28ms4208 KiB
26Runtime error0/28ms4344 KiB
27Runtime error0/28ms4308 KiB
28Accepted2/28ms4348 KiB