Submission #39240157


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;

namespace xxx
{
    internal class Program
    {
        static void Main(string[] args)
        {
            AL.SetCase();
            int N = AL.ReadInt();
            string moves = Console.ReadLine();
            HashSet<(int,int)> poss = new HashSet<(int,int)> ();
            int curx = 0, cury = 0;
            poss.Add((0, 0));
            for (int i = 0; i < N; i++)
            {
                switch (moves[i])
                {
                    case 'R':
                        curx += 1;
                        break;
                    case 'L':
                        curx-=1;
                        break;
                    case 'U':
                        cury += 1;
                        break;
                    case 'D':
                        cury-=1;
                        break;
                }
                if(poss.Contains((curx,cury)))
                {
                    Console.WriteLine("Yes");
                    return;
                }
                poss.Add((curx, cury));
            }
            Console.WriteLine("No");
        }
    }
    static class AL
    {
        public static void SetCase()
        {
#if DEBUG
            Console.WriteLine("Case?");
            var name = Console.ReadLine();
            if (string.IsNullOrWhiteSpace(name))
            {
                Console.WriteLine("Using stdin");
                return;
            }
            var exStdIn = new System.IO.StreamReader($"../../../{name}.txt");
            System.Console.SetIn(exStdIn);
#endif
        }
        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] ReadIntChars()
        {
            // 102 => int[]{1, 0, 2}
            return Console.ReadLine().ToCharArray().Select(c => int.Parse(c.ToString())).ToArray();
        }


        public static int[] ReadIntArray()
        {
            // 12 34 56 => int[]{12, 34, 56}
            return Console.ReadLine().Split().Select(int.Parse).ToArray();
        }

        public static (int a, int b) ReadInt2()
        {
            var ia = ReadIntArray();
            if (ia.Length != 2)
            {
                throw new InvalidCastException();
            }
            return (ia[0], ia[1]);
        }
        public static (int a, int b, int c) ReadInt3()
        {
            var ia = ReadIntArray();
            if (ia.Length != 3)
            {
                throw new InvalidCastException();
            }
            return (ia[0], ia[1], ia[2]);
        }
    }
    public class DefaultDictionary<TKey, TValue> : Dictionary<TKey, TValue> where TValue : new()
    {
        public new TValue this[TKey key]
        {
            get
            {
                if (!TryGetValue(key, out TValue val))
                {
                    val = new TValue();
                    Add(key, val);
                }
                return val;
            }
            set { base[key] = value; }
        }
    }
}

Submission Info

Submission Time
Task C - LRUD Instructions 2
User bugtori
Language C# (.NET Core 3.1.201)
Score 300
Code Size 3203 Byte
Status AC
Exec Time 121 ms
Memory 38668 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 38
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand.txt, hand_01.txt, hand_02.txt, min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand.txt AC 110 ms 38248 KiB
hand_01.txt AC 104 ms 38668 KiB
hand_02.txt AC 95 ms 33156 KiB
min.txt AC 85 ms 27688 KiB
random_01.txt AC 81 ms 28276 KiB
random_02.txt AC 84 ms 28132 KiB
random_03.txt AC 87 ms 28392 KiB
random_04.txt AC 80 ms 27544 KiB
random_05.txt AC 79 ms 28308 KiB
random_06.txt AC 86 ms 27924 KiB
random_07.txt AC 109 ms 38232 KiB
random_08.txt AC 91 ms 30292 KiB
random_09.txt AC 95 ms 38432 KiB
random_10.txt AC 86 ms 30096 KiB
random_11.txt AC 99 ms 38452 KiB
random_12.txt AC 79 ms 28880 KiB
random_13.txt AC 73 ms 28312 KiB
random_14.txt AC 82 ms 27384 KiB
random_15.txt AC 83 ms 28664 KiB
random_16.txt AC 94 ms 28124 KiB
random_17.txt AC 78 ms 28664 KiB
random_18.txt AC 82 ms 28240 KiB
random_19.txt AC 97 ms 28312 KiB
random_20.txt AC 82 ms 27856 KiB
random_21.txt AC 81 ms 28260 KiB
random_22.txt AC 82 ms 28436 KiB
random_23.txt AC 91 ms 38160 KiB
random_24.txt AC 105 ms 38160 KiB
random_25.txt AC 95 ms 38156 KiB
random_26.txt AC 97 ms 38524 KiB
random_27.txt AC 121 ms 38360 KiB
random_28.txt AC 96 ms 38428 KiB
random_29.txt AC 110 ms 38364 KiB
random_30.txt AC 107 ms 38204 KiB
random_31.txt AC 113 ms 38220 KiB
random_32.txt AC 91 ms 33512 KiB
sample_01.txt AC 86 ms 27332 KiB
sample_02.txt AC 85 ms 27596 KiB