結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2024-10-10 23:43:09 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 2,832 bytes |
コンパイル時間 | 965 ms |
コンパイル使用メモリ | 115,660 KB |
実行使用メモリ | 28,732 KB |
最終ジャッジ日時 | 2024-10-10 23:43:21 |
合計ジャッジ時間 | 3,198 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Collections.Generic;using System.Linq;class Program{static string InputPattern = "InputX";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");}}