using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); this.Map = new Dictionary[inpt[0], inpt[1]]; this.Src = new char[inpt[0], inpt[1]]; inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); int defaultSize = inpt[0]; int startY = inpt[1]; int startX = inpt[2]; inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); int goalSize = inpt[0]; int goalY = inpt[1]; int goalX = inpt[2]; int yukiCount = 0; int jimenCount = 0; for(int i=0; i taskQ = new Queue(); taskQ.Enqueue(firstTask); while (taskQ.Count > 0) { TaskItem tsk = taskQ.Dequeue(); int size = tsk.Size; if(this.Map[tsk.Y, tsk.X] != null && this.Map[tsk.Y, tsk.X].ContainsKey(tsk.Size)) { continue; } if(this.Map[tsk.Y, tsk.X] == null) { this.Map[tsk.Y, tsk.X] = new Dictionary(); } this.Map[tsk.Y, tsk.X].Add(size, 1); if(tsk.Y == goalY && tsk.X == goalX && size == goalSize) { break; } int[][] next = new int[4][]; next[0] = new int[]{tsk.Y - 1, tsk.X}; next[1] = new int[]{tsk.Y + 1, tsk.X}; next[2] = new int[]{tsk.Y, tsk.X + 1}; next[3] = new int[]{tsk.Y, tsk.X - 1}; for(int i=0; i= this.Map.GetLength(0) || nextX < 0 || nextX >= this.Map.GetLength(1)) { continue; } int newVal = (this.Src[nextY, nextX] == '*'?size+1:size-1); if(newVal <= 0) { continue; } if(newVal > this.Map.GetLength(0) * this.Map.GetLength(1) + goalSize) { continue; } TaskItem newT = new TaskItem(nextX, nextY, newVal); taskQ.Enqueue(newT); } } string ans = "No"; if(this.Map[goalY, goalX] != null && this.Map[goalY, goalX].ContainsKey(goalSize)) { ans = "Yes"; } Console.WriteLine(ans); } private Dictionary[,] Map; private char[,] Src; private class TaskItem { public int X; public int Y; public int Size; public TaskItem(int x, int y, int size) { this.X = x; this.Y = y; this.Size = size; } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 2 1 1 0 0 4 1 0 * * "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }