40312023-03-09 13:20:22tamasmarkA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 1/509ms5460 KiB
// legkevesebbb atszallas.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>

using namespace std;

struct adat
{
    int kezd, veg, szam;
};

int n, i, j, maxi, a, b,m,akt,h;
vector<adat>x;
vector<int>megold;
bool t;

int main()
{
    cin >> m>>n;
    cin >> a >> b;
    if (a != 1)
    {
        cout << -1;
        return 0;
    }
    else
    {
        x.push_back({ a,b,1 });
        for (i = 1; i <= m - 1; ++i)
        {
            cin >> a >> b;
            x.push_back({ a,b,i+1 });
        }
        akt = 1;
        i = 0;
        while(i<x.size())
        {
            if (x[i].kezd == akt)
            {
                maxi = 0;
                while(x[i].kezd==akt)
                {
                    if (x[i].veg > maxi)
                    {
                        maxi = x[i].veg;
                        h = x[i].szam;
                    }
                    ++i;
                }
                akt = maxi;
                megold.push_back(h);
                if (akt == n)
                {
                    t = true;
                    break;
                }
            }
            else if (x[i].kezd < akt)
            {
                maxi = 0;
                while (x[i].kezd < akt)
                {
                    if (x[i].veg > maxi)
                    {
                        maxi = x[i].veg;
                        h = x[i].szam;
                    }
                    ++i;
                }
                akt = maxi;
                megold.push_back(h);
                if (akt == 9)
                {
                    t = true;
                    break;
                }
            }
            else
            {
                cout << -1;
                return 0;
            }
        }
    }
    if (t)
    {
        cout << megold.size() << "\n";
        for (i = 0; i < megold.size(); ++i)
        {
            cout << megold[i] << " ";
        }
    }
    return 0;
}
/*
6 9
1 2
1 4
2 6
3 4
6 9
7 9
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base1/50
1Wrong answer0/03ms1876 KiB
2Runtime error0/09ms2736 KiB
3Runtime error0/13ms2492 KiB
4Accepted1/13ms2680 KiB
5Wrong answer0/23ms2820 KiB
6Wrong answer0/23ms3164 KiB
7Runtime error0/23ms3192 KiB
8Runtime error0/24ms3664 KiB
9Runtime error0/24ms3472 KiB
10Runtime error0/24ms3596 KiB
11Runtime error0/24ms3664 KiB
12Runtime error0/26ms3860 KiB
13Runtime error0/23ms3712 KiB
14Runtime error0/24ms3748 KiB
15Runtime error0/24ms4128 KiB
16Runtime error0/26ms4404 KiB
17Runtime error0/27ms4520 KiB
18Runtime error0/28ms4620 KiB
19Runtime error0/28ms4728 KiB
20Runtime error0/28ms4788 KiB
21Runtime error0/28ms4780 KiB
22Runtime error0/28ms5040 KiB
23Runtime error0/28ms5108 KiB
24Runtime error0/28ms4992 KiB
25Runtime error0/28ms5064 KiB
26Runtime error0/28ms5248 KiB
27Runtime error0/28ms5460 KiB
28Runtime error0/28ms5456 KiB