71812024-01-02 09:38:06fuhurA lehető legkevesebb átszállás (50 pont)cpp11Wrong answer 40/508ms4552 KiB
#include <iostream>
#include <queue>
using namespace std;

int main()
{
    int N, M, i, sorsz;
    cin>>N>>M;
    int all1[N+1], all2[N+1];
    for (i=1;i<=N;i++)
        cin>>all1[i]>>all2[i];

    queue <int> sorszamok;
    int kezd=1, veg=1, m_all=-1, db=0;
    for (i=1;i<=N&&veg!=M;i++) {
        if (all1[i]>=kezd && all1[i]<=veg) {
            if (m_all<all2[i]) {
                m_all=all2[i];
                sorsz=i;
            }
        }
        else
    //ha nincs benne az eleje az elozo intervallumban
    //[kezd, veg]
        {
            if (m_all==-1) {
                cout<<-1;
                return 0;
            }
            else {
                    sorszamok.push(sorsz);
                    db++;
                    kezd=all1[sorsz];
                    veg=all2[sorsz];
                    m_all=-1;
                    i--;
                }
        }
    }
    if (veg!=M) cout<<-1<<endl;
    else {
    cout<<db-1<<endl;
    while(!sorszamok.empty()) {
        cout<<sorszamok.front()<<" ";
        sorszamok.pop();
    }
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/50
1Accepted0/03ms1812 KiB
2Accepted0/08ms2408 KiB
3Accepted1/13ms2276 KiB
4Accepted1/13ms2288 KiB
5Accepted2/23ms2252 KiB
6Wrong answer0/23ms2380 KiB
7Accepted2/23ms2600 KiB
8Accepted2/23ms2684 KiB
9Accepted2/24ms2816 KiB
10Accepted2/24ms2912 KiB
11Accepted2/24ms3256 KiB
12Accepted2/26ms3332 KiB
13Accepted2/23ms3512 KiB
14Accepted2/24ms3536 KiB
15Accepted2/24ms3652 KiB
16Accepted2/26ms3556 KiB
17Accepted2/27ms3792 KiB
18Accepted2/28ms4116 KiB
19Accepted2/28ms4016 KiB
20Accepted2/28ms3980 KiB
21Accepted2/28ms4132 KiB
22Accepted2/28ms4240 KiB
23Wrong answer0/28ms4212 KiB
24Wrong answer0/28ms4512 KiB
25Accepted2/28ms4296 KiB
26Wrong answer0/28ms4300 KiB
27Wrong answer0/28ms4296 KiB
28Accepted2/28ms4552 KiB