結果

問題 No.424 立体迷路
ユーザー ぴろずぴろず
提出日時 2016-09-22 22:32:50
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,311 bytes
コンパイル時間 2,325 ms
コンパイル使用メモリ 78,220 KB
実行使用メモリ 54,368 KB
最終ジャッジ日時 2024-04-28 18:52:48
合計ジャッジ時間 6,932 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
41,528 KB
testcase_01 AC 117 ms
40,008 KB
testcase_02 AC 128 ms
41,368 KB
testcase_03 AC 129 ms
41,284 KB
testcase_04 AC 131 ms
41,300 KB
testcase_05 AC 119 ms
40,020 KB
testcase_06 AC 132 ms
41,324 KB
testcase_07 AC 133 ms
40,952 KB
testcase_08 AC 134 ms
40,904 KB
testcase_09 AC 133 ms
41,340 KB
testcase_10 AC 134 ms
41,520 KB
testcase_11 AC 131 ms
41,300 KB
testcase_12 AC 132 ms
41,132 KB
testcase_13 AC 132 ms
41,572 KB
testcase_14 AC 139 ms
41,232 KB
testcase_15 AC 130 ms
41,104 KB
testcase_16 AC 134 ms
41,212 KB
testcase_17 AC 138 ms
41,384 KB
testcase_18 AC 139 ms
41,452 KB
testcase_19 AC 138 ms
41,456 KB
testcase_20 AC 144 ms
41,332 KB
testcase_21 AC 132 ms
41,128 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 144 ms
41,140 KB
testcase_25 AC 147 ms
41,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no424;

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	static int[] D = {1,0,-1,0};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] m = new int[h][w];
		int si = sc.nextInt() - 1;
		int sj = sc.nextInt() - 1;
		int gi = sc.nextInt() - 1;
		int gj = sc.nextInt() - 1;
		for(int i=0;i<h;i++) {
			String s = sc.next();
			for(int j=0;j<w;j++) {
				m[i][j] = s.charAt(j) - '0';
			}
		}
		boolean[][] used = new boolean[h][w];
		Queue<Integer> q = new ArrayDeque<>();
		q.offer(si * 100 + sj);
		used[si][sj] = true;
		while(!q.isEmpty()) {
			int c = q.poll();
			int ci = c / 100;
			int cj = c % 100;
			for(int k=0;k<4;k++) {
				int ni = ci + D[k];
				int nj = cj + D[k^1];
				if (ni < 0 || ni >= h || nj < 0 || nj >= w) {
					continue;
				}
				if (Math.abs(m[ci][cj] - m[ni][nj]) <= 1 && !used[ni][nj]) {
					used[ni][nj] = true;
					q.offer(ni * 100 + nj);
				}
				ni += D[k];
				nj += D[k^1];
				if (ni < 0 || ni >= h || nj < 0 || nj >= w) {
					continue;
				}
				if (m[ci][cj] == m[ni][nj] && !used[ni][nj]) {
					used[ni][nj] = true;
					q.offer(ni * 100 + nj);
				}
			}
		}
		System.out.println(used[gi][gj] ? "YES" : "NO");
	}

}
0