76192024-01-10 09:13:02TortelliniJrA lehető legkevesebb átszállás (50 pont)csharpRuntime error 34/50164ms75224 KiB
using System;
using System.Collections.Generic;
using System.Linq;

namespace LegkAtsz
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            List<int>[] allelerh = new List<int>[inp[1] + 1];
            int[,] vonk = new int[inp[0] + 1, 2];
            int von = inp[0];
            int all = inp[1];
            bool bullshit = false;
            for (int i = 1; i <= all; i++)
            {
                allelerh[i] = new List<int>();
            }
            for (int i = 1; i <= von; i++)
            {
                inp = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int u = inp[0]; u <= inp[1]; u++)
                {
                    allelerh[u].Add(i);
                }
                vonk[i, 0] = inp[0];
                vonk[i, 1] = inp[1];
            }
            int jel = 1;
            int locmax = 0;
            int locmaxn = 0;
            List<int> sol = new List<int>();
            while (jel != all)
            {
                for (int i = 0; i < allelerh[jel].Count; i++)
                {
                    if (vonk[allelerh[jel][i], 1] > locmax)
                    {
                        locmax = vonk[allelerh[jel][i], 1];
                        locmaxn = allelerh[jel][i];
                    }
                }
                if (locmax == jel)
                {
                    bullshit = true;
                    break;
                }
                jel = locmax;
                locmax = 0;
                sol.Add(locmaxn);
            }
            if (!bullshit)
            {
                Console.WriteLine(sol.Count - 1);
                foreach (var item in sol)
                {
                    Console.Write(item + " ");
                }
            }
            else
            {
                Console.WriteLine("-1");
            }
            Console.ReadLine();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base34/50
1Accepted0/034ms22072 KiB
2Accepted0/0164ms73676 KiB
3Accepted1/134ms22568 KiB
4Accepted1/132ms23508 KiB
5Accepted2/234ms23636 KiB
6Accepted2/234ms23988 KiB
7Accepted2/246ms36412 KiB
8Accepted2/250ms36708 KiB
9Accepted2/254ms36944 KiB
10Accepted2/264ms40992 KiB
11Accepted2/285ms49896 KiB
12Accepted2/293ms54076 KiB
13Accepted2/252ms37872 KiB
14Accepted2/265ms43388 KiB
15Accepted2/279ms47044 KiB
16Accepted2/296ms53716 KiB
17Accepted2/2128ms66908 KiB
18Accepted2/2134ms66860 KiB
19Accepted2/2155ms74080 KiB
20Accepted2/2160ms75224 KiB
21Runtime error0/2149ms75104 KiB
22Runtime error0/2149ms74992 KiB
23Runtime error0/2108ms74944 KiB
24Runtime error0/2109ms74924 KiB
25Runtime error0/2111ms74892 KiB
26Runtime error0/2104ms74896 KiB
27Runtime error0/2107ms74864 KiB
28Runtime error0/2107ms74848 KiB