79822024-01-12 09:39:27DominikA lehető legkevesebb átszállás (50 pont)csharpWrong answer 8/5078ms31492 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)
            {
                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
base8/50
1Accepted0/028ms20908 KiB
2Wrong answer0/078ms28032 KiB
3Wrong answer0/128ms21788 KiB
4Runtime error0/129ms21116 KiB
5Wrong answer0/228ms22120 KiB
6Runtime error0/230ms21316 KiB
7Wrong answer0/229ms23300 KiB
8Wrong answer0/232ms23708 KiB
9Wrong answer0/232ms24168 KiB
10Wrong answer0/234ms24376 KiB
11Wrong answer0/241ms25256 KiB
12Wrong answer0/243ms25896 KiB
13Wrong answer0/230ms24228 KiB
14Wrong answer0/234ms25028 KiB
15Wrong answer0/239ms25504 KiB
16Wrong answer0/245ms26324 KiB
17Wrong answer0/259ms28612 KiB
18Wrong answer0/264ms29724 KiB
19Wrong answer0/271ms30348 KiB
20Wrong answer0/271ms30772 KiB
21Wrong answer0/278ms31432 KiB
22Wrong answer0/276ms31492 KiB
23Accepted2/243ms27744 KiB
24Accepted2/243ms27868 KiB
25Wrong answer0/245ms28092 KiB
26Accepted2/243ms28236 KiB
27Accepted2/243ms28268 KiB
28Wrong answer0/245ms28096 KiB