76252024-01-10 09:23:45TortelliniJrA lehető legkevesebb átszállás (50 pont)csharpRuntime error 32/50165ms74748 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 || allelerh[jel].Count == 0)
                {
                    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
base32/50
1Accepted0/034ms22452 KiB
2Accepted0/0165ms73592 KiB
3Accepted1/132ms22808 KiB
4Accepted1/132ms23472 KiB
5Accepted2/232ms23812 KiB
6Accepted2/234ms23932 KiB
7Accepted2/246ms35848 KiB
8Accepted2/248ms36064 KiB
9Accepted2/254ms36064 KiB
10Accepted2/265ms40700 KiB
11Accepted2/286ms49176 KiB
12Accepted2/294ms53644 KiB
13Accepted2/250ms37520 KiB
14Accepted2/263ms43560 KiB
15Accepted2/279ms47480 KiB
16Accepted2/297ms54496 KiB
17Accepted2/2128ms66996 KiB
18Accepted2/2134ms67500 KiB
19Accepted2/2150ms74580 KiB
20Runtime error0/2143ms74748 KiB
21Runtime error0/2137ms74564 KiB
22Runtime error0/2137ms73972 KiB
23Runtime error0/296ms73784 KiB
24Runtime error0/2107ms73752 KiB
25Runtime error0/2100ms73752 KiB
26Runtime error0/294ms73348 KiB
27Runtime error0/297ms73296 KiB
28Runtime error0/298ms73344 KiB