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(); int width = inpt[0]; int height = inpt[1]; int otona = inpt[2]; this.Road = new bool[width * height, width * height]; for(int i=0; iint.Parse(a)).ToArray(); if(inpt.Length > 1) { for(int j=1;j taskQ = new Queue(); taskQ.Enqueue(0); while (taskQ.Count > 0) { int pos = taskQ.Dequeue(); int row = pos / width; int col = pos % width; int nextVal = map[pos] + 1; int[][] nextPosList = new int[][] {new int[]{row + 1, col}, new int[] {row -1, col}, new int[]{row, col -1}, new int[]{row, col + 1}}; foreach (int[] nextPos in nextPosList) { if(nextPos[1] < 0 || nextPos[1] >= width || nextPos[0] < 0 || nextPos[0] >= height) { continue; } int nPos = nextPos[0] * width + nextPos[1]; if(!this.Road[pos, nPos]) { continue; } if(map[nPos] <= nextVal) { continue; } map[nPos] = nextVal; if(nPos == width * height - 1) { continue; } taskQ.Enqueue(nPos); } } int ans = map[width * height - 1]; if(ans == int.MaxValue) { Console.WriteLine("Odekakedekinai.."); return; } Console.WriteLine(ans); } private bool[,] Road; public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 3 3 2 2 0 1 4 2 4 7 8 "; 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(); } }