Submission #1315911


Source Code Expand

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

namespace AIZU
{
	struct V {
		public int y;
		public int x;
		public int l;
		public V(int a, int b, int c) { y = a;x = b; l = c; }
		public static V operator +(V a, V b) {
			return new V(a.y + b.y, a.x + b.x, Math.Max(a.l,b.l));
		}
	}
	class Program
	{
		#region Reserve
		static int cin() { return cin(-1); }
		static int cin(int D)
		{
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static int[] cins(char spliter)
		{
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			int[] Res = new int[ss.Length];
			int g;
			for (int i = 0; i < ss.Length; i++) {
				if (int.TryParse(ss[i], out g))
					Res[i] = g;
			}
			return Res;
		}
		static int[] cins() { return cins(' '); }
		static long[] lins(char spliter)
		{
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new long[] { };
			string[] ss = s.Split(spliter);
			long[] Res = new long[ss.Length];
			long g;
			for (int i = 0; i < ss.Length; i++) {
				if (long.TryParse(ss[i], out g))
					Res[i] = g;
			}
			return Res;
		}
		static long[] lins() { return lins(' '); }
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		#endregion
		static bool[,] Pass;
		static bool ONG(V v)
		{
			return Pass[v.y, v.x];
		}
		static void Main(string[] args)
		{
			int[] I = cins();
			int R = I[0], C = I[1];
			Pass = new bool[R, C]; ;
			I = cins();
			int sy = I[0] - 1, sx = I[1] - 1;
			I = cins();
			int gy = I[0] - 1, gx = I[1] - 1;
			string Road;
			for (int iop = 0; iop < R; iop++) {
				Road = Console.ReadLine();
				for (int jop = 0; jop < C; jop++) {
					Pass[iop, jop] = Road[jop] == '.';
				}
			}
			HashSet<V> History = new HashSet<V>();
			Queue<V> Frontier = new Queue<V>();
			int[][] Adja = { new int[]{ 0, 1 }, new int[] { 1, 0 }, new int[] { -1, 0 }, new int[] { 0, -1 } };
			Frontier.Enqueue(new V(sy, sx, 0));
			int Res=0;
			while (Frontier.Count != 0) {
				V v = Frontier.Dequeue();
				foreach (int[] J in Adja) {
					V v1 = v + new V(J[0], J[1], v.l+1);
					if (v1.y == gy && v1.x == gx) { Res = v1.l;goto JK; }
					if (ONG(v1)&&!History.Contains(v1)) {
						Frontier.Enqueue(v1);
						History.Add(v1);
					}
				}
			}
			JK:
			print(Res);
			Console.ReadLine();
		}
	}
}

Submission Info

Submission Time
Task C - 幅優先探索
User sa8
Language C# (Mono 4.6.2.0)
Score 0
Code Size 2579 Byte
Status TLE
Exec Time 2108 ms
Memory 22600 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
TLE × 1
AC × 15
TLE × 10
Set Name Test Cases
Sample subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt
All subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt
Case Name Status Exec Time Memory
subtask0_sample01.txt AC 30 ms 9556 KB
subtask0_sample02.txt AC 28 ms 9428 KB
subtask0_sample03.txt TLE 2108 ms 16396 KB
subtask1_01.txt TLE 2108 ms 20548 KB
subtask1_02.txt TLE 2108 ms 22600 KB
subtask1_03.txt AC 451 ms 17152 KB
subtask1_04.txt TLE 2108 ms 18456 KB
subtask1_05.txt AC 179 ms 16300 KB
subtask1_06.txt TLE 2108 ms 16516 KB
subtask1_07.txt AC 29 ms 9516 KB
subtask1_08.txt AC 50 ms 15820 KB
subtask1_09.txt AC 656 ms 17156 KB
subtask1_10.txt AC 178 ms 14216 KB
subtask1_11.txt TLE 2108 ms 16424 KB
subtask1_12.txt AC 184 ms 14140 KB
subtask1_13.txt AC 415 ms 16272 KB
subtask1_14.txt AC 29 ms 9388 KB
subtask1_15.txt AC 906 ms 17596 KB
subtask1_16.txt AC 1183 ms 15108 KB
subtask1_17.txt AC 1503 ms 16204 KB
subtask1_18.txt AC 1126 ms 17152 KB
subtask1_19.txt TLE 2108 ms 18848 KB
subtask1_20.txt TLE 2108 ms 22596 KB
subtask1_21.txt TLE 2108 ms 20712 KB
subtask1_22.txt TLE 2108 ms 19428 KB