Submission #420279


Source Code Expand

import java.io.*;
import java.util.*;
import java.lang.ArrayIndexOutOfBoundsException;
import java.math.BigInteger;

/**
 * @author yoshikyoto
 */
class Main extends MyUtil {
	public static void main(String[] args) throws Exception {
		int h = readIntMap(0);
		int w = readIntMap(1);
		char[][] c = new char[h][];
		for (int i = 0; i < h; i++) {
			c[i] = readLine().toCharArray();
		}
		
		int sh = 0, sw = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if(c[i][j] =='s'){
					sh = i;
					sw = j;
				}
			}
		}
		
		if(dfs(sh, sw, c)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
	
	static int[] di = {1, -1, 0, 0};
	static int[] dj = {0, 0, 1, -1}; 
	static boolean dfs(int i, int j, char[][] c){
		for (int k = 0; k < 4; k++) {
			try{
				int ni = i + di[k];
				int nj = j + dj[k];
				if(c[ni][nj] == 'g'){
					return true;
				}else if(c[ni][nj] == '.'){
					c[ni][nj] = '#';
					if(dfs(i+di[k], j+dj[k], c)){
						return true;
					}
				}
			}catch(ArrayIndexOutOfBoundsException e){}
		}
		return false;
	}
}



// --- ここから下はライブラリ ----------
/**
 * MyUtil
 * @author yoshikyoto
 */
class MyUtil {
	public static int toInt(boolean[] a){
		int pow = 1, ret = 0, l = a.length;
		for(int i = 0; i < l; i++){
			if(a[i]) ret += pow;
			pow *= 2;
		}
		return ret;
	}
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static int ins[];
	public static int[] readIntMap() throws IOException{return parseInt(readLine().split(" "));}
	public static int readIntMap(int i) throws Exception{
		if(i == 0) ins = readIntMap();
		return ins[i];
	}
	public static int[][] readIntMap(int n, int m) throws IOException{
		int[][] ret = new int[n][];
		for(int i = 0; i < n; i++) ret[i] = readIntMap();
		return ret;
	}
	public static int[] readIntToMap(int n) throws IOException{
		int[] ret = new int[n];
		for(int i = 0; i < n; i++) ret[i] = readInt();
		return ret;
	}
	public static int[] readNoDistIntMap() throws IOException{
		String[] strs = readLine().split("");
		int l = strs.length;
		int[] ret = new int[l-1];
		for(int i = 1; i < l; i++)
			ret[i-1] = parseInt(strs[i]);
		return ret;
	}
	public static String readLine() throws IOException{return br.readLine();}
	public static int readInt() throws IOException{return Integer.parseInt(br.readLine());}
	public static int[] parseInt(String[] arr){
		int[] res = new int[arr.length];
		for(int i = 0; i < arr.length; i++)res[i] = Integer.parseInt(arr[i]);
		return res;
	}
	public static double[] parseDouble(String[] arr){
		double[] res = new double[arr.length];
		for(int i = 0; i < arr.length; i++)res[i] = Double.parseDouble(arr[i]);
		return res;
	}
	public static boolean[] parseBool(String[] arr){
		int[] t = parseInt(arr);
		boolean[] res = new boolean[t.length];
		for(int i = 0; i < t.length; i++){
			if(t[i] == 1){res[i] = true;
			}else{res[i] = false;}
		}
		return res;
	}
	public static int parseInt(Object o){
		return Integer.parseInt(o.toString());
	}
}

Submission Info

Submission Time
Task A - 深さ優先探索
User yoshikyoto
Language Java (OpenJDK 1.7.0)
Score 100
Code Size 3175 Byte
Status AC
Exec Time 535 ms
Memory 34580 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 5
AC × 83
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt
All 00_min_01.txt, 00_min_02.txt, 00_min_03.txt, 00_min_04.txt, 00_min_05.txt, 00_min_06.txt, 00_min_07.txt, 00_min_08.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 01_rnd_10.txt, 01_rnd_11.txt, 01_rnd_12.txt, 01_rnd_13.txt, 01_rnd_14.txt, 01_rnd_15.txt, 01_rnd_16.txt, 01_rnd_17.txt, 01_rnd_18.txt, 01_rnd_19.txt, 02_rndhard_00.txt, 02_rndhard_01.txt, 02_rndhard_02.txt, 02_rndhard_03.txt, 02_rndhard_04.txt, 02_rndhard_05.txt, 02_rndhard_06.txt, 02_rndhard_07.txt, 02_rndhard_08.txt, 02_rndhard_09.txt, 02_rndhard_10.txt, 02_rndhard_11.txt, 02_rndhard_12.txt, 02_rndhard_13.txt, 02_rndhard_14.txt, 02_rndhard_15.txt, 02_rndhard_16.txt, 02_rndhard_17.txt, 02_rndhard_18.txt, 02_rndhard_19.txt, 02_rndhard_20.txt, 02_rndhard_21.txt, 02_rndhard_22.txt, 02_rndhard_23.txt, 02_rndhard_24.txt, 02_rndhard_25.txt, 02_rndhard_26.txt, 02_rndhard_27.txt, 02_rndhard_28.txt, 02_rndhard_29.txt, 02_rndhard_30.txt, 02_rndhard_31.txt, 02_rndhard_32.txt, 02_rndhard_33.txt, 02_rndhard_34.txt, 02_rndhard_35.txt, 02_rndhard_36.txt, 02_rndhard_37.txt, 02_rndhard_38.txt, 02_rndhard_39.txt, 03_rndhardsmall_00.txt, 03_rndhardsmall_01.txt, 03_rndhardsmall_02.txt, 03_rndhardsmall_03.txt, 03_rndhardsmall_04.txt, 03_rndhardsmall_05.txt, 03_rndhardsmall_06.txt, 03_rndhardsmall_07.txt, 03_rndhardsmall_08.txt, 03_rndhardsmall_09.txt
Case Name Status Exec Time Memory
00_min_01.txt AC 322 ms 22624 KB
00_min_02.txt AC 324 ms 22636 KB
00_min_03.txt AC 324 ms 22636 KB
00_min_04.txt AC 323 ms 22544 KB
00_min_05.txt AC 323 ms 22540 KB
00_min_06.txt AC 327 ms 22624 KB
00_min_07.txt AC 328 ms 22532 KB
00_min_08.txt AC 339 ms 22524 KB
00_sample_01.txt AC 326 ms 22516 KB
00_sample_02.txt AC 325 ms 22540 KB
00_sample_03.txt AC 325 ms 22636 KB
00_sample_04.txt AC 324 ms 22544 KB
00_sample_05.txt AC 324 ms 22560 KB
01_rnd_00.txt AC 376 ms 26796 KB
01_rnd_01.txt AC 405 ms 30316 KB
01_rnd_02.txt AC 400 ms 29180 KB
01_rnd_03.txt AC 404 ms 32000 KB
01_rnd_04.txt AC 398 ms 30148 KB
01_rnd_05.txt AC 381 ms 26716 KB
01_rnd_06.txt AC 407 ms 28992 KB
01_rnd_07.txt AC 410 ms 30212 KB
01_rnd_08.txt AC 385 ms 26956 KB
01_rnd_09.txt AC 386 ms 26712 KB
01_rnd_10.txt AC 403 ms 27736 KB
01_rnd_11.txt AC 385 ms 26864 KB
01_rnd_12.txt AC 413 ms 29596 KB
01_rnd_13.txt AC 403 ms 29104 KB
01_rnd_14.txt AC 384 ms 26696 KB
01_rnd_15.txt AC 417 ms 28676 KB
01_rnd_16.txt AC 398 ms 27252 KB
01_rnd_17.txt AC 416 ms 28852 KB
01_rnd_18.txt AC 409 ms 27528 KB
01_rnd_19.txt AC 412 ms 34580 KB
02_rndhard_00.txt AC 390 ms 27056 KB
02_rndhard_01.txt AC 393 ms 27264 KB
02_rndhard_02.txt AC 412 ms 27600 KB
02_rndhard_03.txt AC 411 ms 27244 KB
02_rndhard_04.txt AC 381 ms 27076 KB
02_rndhard_05.txt AC 381 ms 26816 KB
02_rndhard_06.txt AC 382 ms 26872 KB
02_rndhard_07.txt AC 389 ms 26952 KB
02_rndhard_08.txt AC 378 ms 26840 KB
02_rndhard_09.txt AC 384 ms 27148 KB
02_rndhard_10.txt AC 387 ms 27224 KB
02_rndhard_11.txt AC 384 ms 27096 KB
02_rndhard_12.txt AC 380 ms 26644 KB
02_rndhard_13.txt AC 400 ms 27104 KB
02_rndhard_14.txt AC 385 ms 27288 KB
02_rndhard_15.txt AC 387 ms 26956 KB
02_rndhard_16.txt AC 376 ms 26760 KB
02_rndhard_17.txt AC 385 ms 26756 KB
02_rndhard_18.txt AC 393 ms 27128 KB
02_rndhard_19.txt AC 375 ms 26620 KB
02_rndhard_20.txt AC 395 ms 26856 KB
02_rndhard_21.txt AC 379 ms 26644 KB
02_rndhard_22.txt AC 389 ms 27072 KB
02_rndhard_23.txt AC 385 ms 26868 KB
02_rndhard_24.txt AC 376 ms 26772 KB
02_rndhard_25.txt AC 384 ms 26920 KB
02_rndhard_26.txt AC 404 ms 26932 KB
02_rndhard_27.txt AC 383 ms 26812 KB
02_rndhard_28.txt AC 419 ms 27084 KB
02_rndhard_29.txt AC 402 ms 26492 KB
02_rndhard_30.txt AC 535 ms 27000 KB
02_rndhard_31.txt AC 374 ms 27024 KB
02_rndhard_32.txt AC 372 ms 26944 KB
02_rndhard_33.txt AC 398 ms 27272 KB
02_rndhard_34.txt AC 374 ms 26620 KB
02_rndhard_35.txt AC 372 ms 26712 KB
02_rndhard_36.txt AC 372 ms 26704 KB
02_rndhard_37.txt AC 368 ms 26412 KB
02_rndhard_38.txt AC 378 ms 26972 KB
02_rndhard_39.txt AC 370 ms 26844 KB
03_rndhardsmall_00.txt AC 324 ms 22540 KB
03_rndhardsmall_01.txt AC 318 ms 22412 KB
03_rndhardsmall_02.txt AC 318 ms 22560 KB
03_rndhardsmall_03.txt AC 325 ms 22588 KB
03_rndhardsmall_04.txt AC 321 ms 22552 KB
03_rndhardsmall_05.txt AC 325 ms 22612 KB
03_rndhardsmall_06.txt AC 326 ms 22632 KB
03_rndhardsmall_07.txt AC 325 ms 22540 KB
03_rndhardsmall_08.txt AC 318 ms 22416 KB
03_rndhardsmall_09.txt AC 318 ms 22504 KB