結果

問題 No.240 ナイト散歩
ユーザー 明智重蔵明智重蔵
提出日時 2015-09-12 10:26:32
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 2,831 bytes
コンパイル時間 1,002 ms
コンパイル使用メモリ 114,948 KB
実行使用メモリ 28,628 KB
最終ジャッジ日時 2024-04-16 19:35:27
合計ジャッジ時間 3,161 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
26,572 KB
testcase_01 AC 34 ms
26,444 KB
testcase_02 AC 33 ms
26,452 KB
testcase_03 AC 34 ms
28,252 KB
testcase_04 AC 33 ms
26,332 KB
testcase_05 AC 35 ms
28,120 KB
testcase_06 AC 34 ms
26,440 KB
testcase_07 AC 34 ms
26,336 KB
testcase_08 AC 34 ms
26,580 KB
testcase_09 AC 34 ms
26,316 KB
testcase_10 AC 34 ms
28,276 KB
testcase_11 AC 34 ms
26,460 KB
testcase_12 AC 34 ms
26,672 KB
testcase_13 AC 34 ms
26,336 KB
testcase_14 AC 34 ms
26,312 KB
testcase_15 AC 34 ms
26,336 KB
testcase_16 AC 34 ms
24,508 KB
testcase_17 AC 34 ms
26,468 KB
testcase_18 AC 34 ms
28,476 KB
testcase_19 AC 33 ms
24,244 KB
testcase_20 AC 34 ms
26,464 KB
testcase_21 AC 34 ms
26,412 KB
testcase_22 AC 35 ms
28,628 KB
testcase_23 AC 33 ms
26,416 KB
testcase_24 AC 34 ms
28,108 KB
testcase_25 AC 33 ms
26,208 KB
testcase_26 AC 34 ms
26,440 KB
testcase_27 AC 33 ms
26,336 KB
testcase_28 AC 34 ms
26,084 KB
testcase_29 AC 33 ms
26,336 KB
testcase_30 AC 35 ms
28,376 KB
testcase_31 AC 34 ms
28,372 KB
testcase_32 AC 34 ms
28,116 KB
testcase_33 AC 34 ms
28,240 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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

class Program
{
    static string InputPattern = "Input5";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("1 2");
            //YES
            //1歩で移動可能である。
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5 -4");
            //YES
            //ちょうど3歩で移動できる。
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("100 100");
            //NO
            //3歩以内ではたどり着けない。
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("0 0");
            //YES
            //1歩も動かないで辿りつける。
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct JyoutaiDef
    {
        internal int Level;
        internal int CurrX;
        internal int CurrY;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(A => int.Parse(A)).ToArray();
        int X = wkArr[0];
        int Y = wkArr[1];

        var VisitedSet = new HashSet<string>();

        var stk = new Stack<JyoutaiDef>();
        JyoutaiDef WillPush;
        WillPush.Level = 0;
        WillPush.CurrX = WillPush.CurrY = 0;
        stk.Push(WillPush);
        VisitedSet.Add(string.Format("({0},{1})", 0, 0));

        while (stk.Count > 0) {
            JyoutaiDef Popped = stk.Pop();

            //クリア処理
            if (Popped.Level == 3) continue;

            Action<int, int> PushSyori = (pNewX, pNewY) =>
            {
                //再訪不可
                string wkStr = string.Format("({0},{1})", pNewX, pNewY);
                if (VisitedSet.Add(wkStr) == false) return;

                WillPush.Level = Popped.Level + 1;
                WillPush.CurrX = pNewX;
                WillPush.CurrY = pNewY;
                stk.Push(WillPush);
            };

            PushSyori(Popped.CurrX - 2, Popped.CurrY - 1);
            PushSyori(Popped.CurrX - 2, Popped.CurrY + 1);
            PushSyori(Popped.CurrX - 1, Popped.CurrY - 2);
            PushSyori(Popped.CurrX - 1, Popped.CurrY + 2);
            PushSyori(Popped.CurrX + 1, Popped.CurrY - 2);
            PushSyori(Popped.CurrX + 1, Popped.CurrY + 2);
            PushSyori(Popped.CurrX + 2, Popped.CurrY - 1);
            PushSyori(Popped.CurrX + 2, Popped.CurrY + 1);
        }
        bool CanVisit = VisitedSet.Contains(string.Format("({0},{1})", X, Y));
        Console.WriteLine(CanVisit ? "YES" : "NO");
    }
}
0