79932024-01-12 09:46:20DominikA lehető legkevesebb átszállás (50 pont)csharpWrong answer 9/5079ms30456 KiB
using System;

namespace atszallasok
{
    class Program
    {
        static int[] Findlongest(int indulo, int[,] vonatallomasok,int N)
        {
            int[] longestdata = new int[3];
            longestdata[0] = -1;
            longestdata[1] = -1;
            for (int i = 0; i < N; i++)
            {
                if (vonatallomasok[i, 0] == indulo)
                {
                    longestdata[0] = vonatallomasok[i, 1] - vonatallomasok[i, 0];
                    longestdata[1] = vonatallomasok[i,1];
                    longestdata[2] = i+1;
                }
                else if (vonatallomasok[i,1]>indulo&&vonatallomasok[i,0]<=indulo)
                {
                    longestdata[0] = vonatallomasok[i, 1] - vonatallomasok[i, 0];
                    longestdata[1] = vonatallomasok[i, 1];
                    longestdata[2] = i+1;
                }
            }
            return longestdata;
        }

        static void Main(string[] args)
        {
            string[] vonatinfo = Console.ReadLine().Split(' ');
            int N = int.Parse(vonatinfo[0]);
            int allomasdb = int.Parse(vonatinfo[1]);
            int[,] vonatallomasok = new int[N, 2];
            for (int i = 0; i < N; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                vonatallomasok[i, 0] = int.Parse(line[0]);
                vonatallomasok[i, 1] = int.Parse(line[1]);
            }
            int megallok = 0;
            int[] megalloid = new int[N];
            int[] trainid = new int[N];
            int lateststop=1;
            while (true)
            {
                int[] longestdata = Findlongest(lateststop,vonatallomasok,N);
                lateststop = longestdata[1];
                megalloid[megallok] = lateststop;
                trainid[megallok] = longestdata[2];
                megallok++;
                if (lateststop==-1||lateststop==allomasdb)
                {
                    break;
                }
            }
            if (megalloid[megallok]==-1||megalloid[megallok-1]!=allomasdb)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine((megallok-1));
                string hasznaltvonatid = string.Empty;
                for (int i = 0; i < megallok; i++)
                {
                    hasznaltvonatid += trainid[i];
                    if (megallok!=i+1)
                    {
                        hasznaltvonatid += " ";
                    }
                }
                Console.WriteLine(hasznaltvonatid);
            }
            Console.ReadKey();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base9/50
1Accepted0/028ms20964 KiB
2Wrong answer0/078ms27868 KiB
3Accepted1/128ms21480 KiB
4Runtime error0/129ms21192 KiB
5Wrong answer0/228ms22408 KiB
6Runtime error0/230ms21848 KiB
7Wrong answer0/230ms23116 KiB
8Wrong answer0/230ms23236 KiB
9Wrong answer0/232ms23568 KiB
10Wrong answer0/234ms24376 KiB
11Wrong answer0/241ms24920 KiB
12Wrong answer0/243ms26008 KiB
13Wrong answer0/232ms24008 KiB
14Wrong answer0/235ms24780 KiB
15Wrong answer0/239ms25500 KiB
16Wrong answer0/245ms25952 KiB
17Wrong answer0/259ms28440 KiB
18Wrong answer0/265ms28896 KiB
19Wrong answer0/271ms29100 KiB
20Wrong answer0/274ms29880 KiB
21Wrong answer0/279ms30456 KiB
22Wrong answer0/276ms30404 KiB
23Accepted2/243ms26816 KiB
24Accepted2/243ms26876 KiB
25Wrong answer0/245ms26940 KiB
26Accepted2/243ms26676 KiB
27Accepted2/246ms26796 KiB
28Wrong answer0/245ms26932 KiB