結果

問題 No.424 立体迷路
ユーザー kuuso1kuuso1
提出日時 2016-09-22 22:55:46
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 2,363 bytes
コンパイル時間 2,328 ms
コンパイル使用メモリ 107,628 KB
実行使用メモリ 22,956 KB
最終ジャッジ日時 2023-09-18 16:48:45
合計ジャッジ時間 5,068 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
21,016 KB
testcase_01 AC 58 ms
22,956 KB
testcase_02 AC 58 ms
22,868 KB
testcase_03 AC 58 ms
20,800 KB
testcase_04 AC 59 ms
20,888 KB
testcase_05 AC 58 ms
20,852 KB
testcase_06 AC 57 ms
22,772 KB
testcase_07 AC 58 ms
20,776 KB
testcase_08 AC 57 ms
20,788 KB
testcase_09 AC 58 ms
20,792 KB
testcase_10 AC 57 ms
20,828 KB
testcase_11 AC 57 ms
20,812 KB
testcase_12 AC 57 ms
20,832 KB
testcase_13 AC 58 ms
22,768 KB
testcase_14 AC 58 ms
20,860 KB
testcase_15 AC 59 ms
22,948 KB
testcase_16 AC 58 ms
20,784 KB
testcase_17 AC 59 ms
22,804 KB
testcase_18 AC 59 ms
22,780 KB
testcase_19 AC 60 ms
22,848 KB
testcase_20 AC 59 ms
20,888 KB
testcase_21 AC 58 ms
20,892 KB
testcase_22 AC 58 ms
22,864 KB
testcase_23 AC 58 ms
20,804 KB
testcase_24 AC 59 ms
20,836 KB
testcase_25 AC 59 ms
22,768 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Func<int,int,bool> InRange = (r,c) =>{
			return 0<=r && r<H && 0 <= c && c <W;
		};
		int[][] min = new int[H][];
		for(int i=0;i<H;i++){
			min[i] = new int[W];
			for(int j=0;j<W;j++){
				min[i][j] = -1;
			}
		}
		
		int[] dy = new int[]{0,-1,0,1};
		int[] dx = new int[]{1,0,-1,0};
		
		int md = 1<<10;
		Func<int,int,int> enc = (r,c)=> r*md + c;
		
		
		Func<int,int,bool> canGo1 = (from,to) => {
			return Math.Abs(S[from/md][from%md] - S[to/md][to%md])<=1;
		};
		Func<int,int,bool> canGo2 = (from,to) => {
			return (S[from/md][from%md] == S[to/md][to%md]) && (S[from/md][from%md] > S[((from + to)/2)/md][((from + to)/2)%md]);
		};
		
		Queue<int> Q = new Queue<int>();
		Q.Enqueue(enc(sy,sx));
		min[sy][sx] = 0;
		while(Q.Count>0){
			var p = Q.Dequeue();
			int r = p/md;
			int c = p%md;
			for(int t=0;t<4;t++){
				
				int ny = r + dy[t];
				int nx = c + dx[t];
				if(InRange(ny,nx) && canGo1(p,enc(ny,nx)) && min[ny][nx] == -1){
					min[ny][nx] = min[r][c] + 1;
					Q.Enqueue(enc(ny,nx));
				}
				ny = r + 2*dy[t];
				nx = c + 2*dx[t];
				if(InRange(ny,nx) && canGo2(p,enc(ny,nx)) && min[ny][nx] == -1){
					min[ny][nx] = min[r][c] + 1;
					Q.Enqueue(enc(ny,nx));
				}
			}
		}
		Console.WriteLine(min[gy][gx] == -1?"NO":"YES");
		
		
		
	}
	int H,W;
	int sx,sy,gx,gy;
	String[] S;
	public Sol(){
		var d = ria();
		H = d[0];
		W = d[1];
		d = ria();
		sy = d[0]-1;
		sx = d[1]-1;
		gy = d[2]-1;
		gx = d[3]-1;
		S = new String[H];
		for(int i=0;i<H;i++){
			S[i] = rs();
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0