Submission #7134748


Source Code Expand

Copy
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int hMax = sc.nextInt();
		int wMax = sc.nextInt();

		String[][] townMap = new String[wMax][hMax];
		boolean[][] reached = new boolean[wMax][hMax];
		int wg = 0;
		int hg = 0;

		for (int i = 0; i < hMax; i++) {
			String[] line = sc.next().split("");
			for (int j = 0; j < wMax; j++) {
				townMap[j][i] = line[j];
				System.out.println(j+" "+i);
				System.out.print(townMap[j][i]);

				if (townMap[j][i].equals("g")){
					wg = j;
					hg = i;
				}
			}
			if(sc.hasNext()) sc.hasNextLine();
		}

		search(0, 0, wMax, hMax, reached, townMap);

		if (reached[wg][hg]) System.out.println("Yes");
		else System.out.println("No");
	}

	private static void search(int x, int y, int wMax, int hMax, boolean[][] reached, String[][] townMap) {

		if (x < 0 || y < 0 || x > wMax - 1 || y > hMax - 1) return;
		if (townMap[x][y].equals("#")) return;
		if (reached[x][y]) return;

		reached[x][y] = true;

		search(x + 1, y , wMax, hMax, reached, townMap);
		search(x - 1, y , wMax, hMax, reached, townMap);
		search(x, y + 1 , wMax, hMax, reached, townMap);
		search(x, y - 1 , wMax, hMax, reached, townMap);
	}}

Submission Info

Submission Time
Task A - 深さ優先探索
User sig1166
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 1314 Byte
Status
Exec Time 2105 ms
Memory 77016 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt
All 0 / 100 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 92 ms 20948 KB
00_min_02.txt 94 ms 21716 KB
00_min_03.txt 94 ms 17108 KB
00_min_04.txt 95 ms 19796 KB
00_min_05.txt 95 ms 21972 KB
00_min_06.txt 96 ms 20820 KB
00_min_07.txt 95 ms 20692 KB
00_min_08.txt 95 ms 21712 KB
00_sample_01.txt 95 ms 23892 KB
00_sample_02.txt 95 ms 18640 KB
00_sample_03.txt 100 ms 18772 KB
00_sample_04.txt 102 ms 21716 KB
00_sample_05.txt 94 ms 18772 KB
01_rnd_00.txt 1960 ms 55456 KB
01_rnd_01.txt 1982 ms 77016 KB
01_rnd_02.txt 2029 ms 63032 KB
01_rnd_03.txt 1994 ms 66036 KB
01_rnd_04.txt 1967 ms 60688 KB
01_rnd_05.txt 1992 ms 58684 KB
01_rnd_06.txt 1987 ms 61904 KB
01_rnd_07.txt 1982 ms 58276 KB
01_rnd_08.txt 1947 ms 59716 KB
01_rnd_09.txt 2066 ms 60860 KB
01_rnd_10.txt 1993 ms 58100 KB
01_rnd_11.txt 2020 ms 58240 KB
01_rnd_12.txt 2089 ms 70856 KB
01_rnd_13.txt 1991 ms 69412 KB
01_rnd_14.txt 1961 ms 58684 KB
01_rnd_15.txt 1939 ms 60596 KB
01_rnd_16.txt 1973 ms 59236 KB
01_rnd_17.txt 1938 ms 60364 KB
01_rnd_18.txt 1932 ms 58208 KB
01_rnd_19.txt 2093 ms 76452 KB
02_rndhard_00.txt 2105 ms 57168 KB
02_rndhard_01.txt 1985 ms 58244 KB
02_rndhard_02.txt 1999 ms 58832 KB
02_rndhard_03.txt 1930 ms 59264 KB
02_rndhard_04.txt 1968 ms 59292 KB
02_rndhard_05.txt 1959 ms 58120 KB
02_rndhard_06.txt 1924 ms 60628 KB
02_rndhard_07.txt 1951 ms 62672 KB
02_rndhard_08.txt 1954 ms 56480 KB
02_rndhard_09.txt 1975 ms 56580 KB
02_rndhard_10.txt 1971 ms 58104 KB
02_rndhard_11.txt 1969 ms 56716 KB
02_rndhard_12.txt 1970 ms 59692 KB
02_rndhard_13.txt 1996 ms 58060 KB
02_rndhard_14.txt 2094 ms 58196 KB
02_rndhard_15.txt 1941 ms 56460 KB
02_rndhard_16.txt 1997 ms 56832 KB
02_rndhard_17.txt 1974 ms 56632 KB
02_rndhard_18.txt 1944 ms 60616 KB
02_rndhard_19.txt 1949 ms 58296 KB
02_rndhard_20.txt 2015 ms 59168 KB
02_rndhard_21.txt 1966 ms 56512 KB
02_rndhard_22.txt 1997 ms 59708 KB
02_rndhard_23.txt 1933 ms 60688 KB
02_rndhard_24.txt 1938 ms 60592 KB
02_rndhard_25.txt 1983 ms 60832 KB
02_rndhard_26.txt 1987 ms 57064 KB
02_rndhard_27.txt 1994 ms 56748 KB
02_rndhard_28.txt 1966 ms 55288 KB
02_rndhard_29.txt 1975 ms 57872 KB
02_rndhard_30.txt 1997 ms 58984 KB
02_rndhard_31.txt 1954 ms 57140 KB
02_rndhard_32.txt 2059 ms 59056 KB
02_rndhard_33.txt 1975 ms 61240 KB
02_rndhard_34.txt 1994 ms 59108 KB
02_rndhard_35.txt 1962 ms 58092 KB
02_rndhard_36.txt 1949 ms 59420 KB
02_rndhard_37.txt 2001 ms 56408 KB
02_rndhard_38.txt 1968 ms 59836 KB
02_rndhard_39.txt 1929 ms 60228 KB
03_rndhardsmall_00.txt 97 ms 21844 KB
03_rndhardsmall_01.txt 99 ms 19668 KB
03_rndhardsmall_02.txt 101 ms 19284 KB
03_rndhardsmall_03.txt 99 ms 18772 KB
03_rndhardsmall_04.txt 96 ms 19924 KB
03_rndhardsmall_05.txt 98 ms 20564 KB
03_rndhardsmall_06.txt 94 ms 21972 KB
03_rndhardsmall_07.txt 97 ms 19668 KB
03_rndhardsmall_08.txt 98 ms 18900 KB
03_rndhardsmall_09.txt 96 ms 21844 KB