using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input5"; static List GetInputList() { var WillReturn = new List(); 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 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(); var stk = new Stack(); 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 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"); } }