34222023-02-27 13:50:42vááááÁruszállítás üres szakaszaicsharpTime limit exceeded 44/50337ms33928 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aruszallitas
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            int N = int.Parse(a.Split()[0]);
            int M = int.Parse(a.Split()[1]);
            int[] kez = new int[M];
            int[] veg = new int[M];
            for (int i = 0; i < M; i++)
            {
                a = Console.ReadLine();
                kez[i] = (int.Parse(a.Split()[0]));
                veg[i] = (int.Parse(a.Split()[1]));
            }
            Array.Sort(kez);
            Array.Sort(veg);
            int ck = 0, cv = 0;
            int ures = 0;
            bool fures = false;
            int k = 1;
            int ki = 0;
            bool kozt = false;
            while(true)
            {
                if (k == N + 1)
                    break;
                ures = 0;
                if (ck == cv)
                    ures++;
                while (true)
                {
                    if (ck == M)
                        break;
                    if (kez[ck] == k)
                    {
                        ck++;
                    }
                    if (ck != M)
                    {
                        if (kez[ck] != k)
                            break;
                    }
                }
                while (true)
                {
                    if (cv == M)
                        break;
                    if (veg[cv] == k)
                    {
                        cv++;
                    }
                    if (cv != M)
                    {
                        if (veg[cv] != k)
                            break;
                    }
                }
                if (ck ==cv)
                    ures++;
                if(ures == 2 && fures == false)
                {
                        fures = true;
                        ki++;
                }
                if (kozt && ck != cv && fures == false)
                {
                    ki++;
                }
                else if (fures == true && ures != 2)
                    fures = false;
                kozt = false;
                if (ck == cv)
                    kozt = true;
                k++;
            }
            Console.WriteLine(ki);
            Console.ReadKey();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base44/50
1Accepted0/030ms20896 KiB
2Time limit exceeded0/0337ms30432 KiB
3Accepted2/228ms21308 KiB
4Accepted2/228ms21928 KiB
5Accepted2/229ms22396 KiB
6Accepted2/228ms22420 KiB
7Accepted2/228ms22568 KiB
8Accepted2/228ms23160 KiB
9Accepted2/230ms23172 KiB
10Accepted2/229ms23168 KiB
11Accepted2/229ms23196 KiB
12Accepted2/230ms23784 KiB
13Accepted3/350ms26812 KiB
14Accepted3/356ms28324 KiB
15Accepted3/346ms26844 KiB
16Accepted3/3261ms32928 KiB
17Accepted3/3264ms32620 KiB
18Accepted3/3298ms32916 KiB
19Accepted3/359ms28560 KiB
20Accepted3/363ms29768 KiB
21Time limit exceeded0/3317ms33356 KiB
22Time limit exceeded0/3321ms33928 KiB