76342024-01-10 09:54:57AGergoA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 40/504ms4768 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+1);
vector<int> vonatEnd(vonatszam+1);
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(id == vonatszam)
        {
            cout << "-1";
            hasEnd = false;
            break;
        }
        else 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
base40/50
1Accepted0/03ms1860 KiB
2Accepted0/04ms2308 KiB
3Accepted1/12ms2180 KiB
4Accepted1/12ms2104 KiB
5Accepted2/23ms2236 KiB
6Wrong answer0/23ms2440 KiB
7Accepted2/23ms2664 KiB
8Accepted2/23ms2888 KiB
9Accepted2/23ms3236 KiB
10Accepted2/23ms3196 KiB
11Accepted2/24ms3456 KiB
12Accepted2/24ms3676 KiB
13Accepted2/23ms3596 KiB
14Accepted2/23ms3864 KiB
15Accepted2/23ms3948 KiB
16Accepted2/24ms4100 KiB
17Accepted2/24ms4332 KiB
18Accepted2/24ms4288 KiB
19Accepted2/24ms4552 KiB
20Accepted2/24ms4584 KiB
21Accepted2/24ms4516 KiB
22Accepted2/24ms4516 KiB
23Wrong answer0/24ms4516 KiB
24Wrong answer0/24ms4768 KiB
25Accepted2/24ms4728 KiB
26Wrong answer0/24ms4728 KiB
27Wrong answer0/24ms4732 KiB
28Accepted2/24ms4728 KiB