結果
問題 | No.424 立体迷路 |
ユーザー | Daigo HIROOKA |
提出日時 | 2018-05-28 04:52:30 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 139 ms / 2,000 ms |
コード長 | 1,276 bytes |
コンパイル時間 | 3,404 ms |
コンパイル使用メモリ | 74,208 KB |
実行使用メモリ | 56,412 KB |
最終ジャッジ日時 | 2023-09-18 17:04:48 |
合計ジャッジ時間 | 7,957 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 129 ms
55,776 KB |
testcase_01 | AC | 129 ms
55,776 KB |
testcase_02 | AC | 131 ms
55,700 KB |
testcase_03 | AC | 130 ms
56,056 KB |
testcase_04 | AC | 134 ms
55,928 KB |
testcase_05 | AC | 128 ms
55,712 KB |
testcase_06 | AC | 127 ms
55,916 KB |
testcase_07 | AC | 126 ms
56,132 KB |
testcase_08 | AC | 127 ms
55,780 KB |
testcase_09 | AC | 128 ms
55,736 KB |
testcase_10 | AC | 127 ms
55,708 KB |
testcase_11 | AC | 130 ms
55,736 KB |
testcase_12 | AC | 129 ms
55,868 KB |
testcase_13 | AC | 131 ms
55,788 KB |
testcase_14 | AC | 130 ms
56,028 KB |
testcase_15 | AC | 131 ms
55,772 KB |
testcase_16 | AC | 130 ms
55,896 KB |
testcase_17 | AC | 137 ms
55,840 KB |
testcase_18 | AC | 138 ms
55,892 KB |
testcase_19 | AC | 135 ms
56,076 KB |
testcase_20 | AC | 136 ms
56,116 KB |
testcase_21 | AC | 129 ms
55,788 KB |
testcase_22 | AC | 129 ms
55,968 KB |
testcase_23 | AC | 128 ms
55,588 KB |
testcase_24 | AC | 135 ms
56,192 KB |
testcase_25 | AC | 139 ms
56,412 KB |
ソースコード
import java.util.*; public class No424{ static int h, w, sx, sy, gx, gy; static String[] B; static int[] dx = {0, 1, 0, -1}; static int[] dy = {1, 0, -1, 0}; static boolean[][] visited; public static void main(String[] args){ Scanner sc = new Scanner(System.in); h = sc.nextInt(); w = sc.nextInt(); sx = sc.nextInt(); sy = sc.nextInt(); gx = sc.nextInt(); gy = sc.nextInt(); B = new String[h]; for(int i = 0; i < h; i++){ B[i] = sc.next(); } visited = new boolean[h][w]; visited[sx-1][sy-1] = true; dfs(sx-1, sy-1); if(visited[gx-1][gy-1]) System.out.println("YES"); else System.out.println("NO"); } private static void dfs(int x, int y){ for(int dir = 0; dir < 4; dir++){ int x1 = x + dx[dir]; int y1 = y + dy[dir]; if(0 <= x1 && x1 < h && 0 <= y1 && y1 < w){ if(Math.abs((int)B[x1].charAt(y1) - (int)B[x].charAt(y)) <= 1 && !visited[x1][y1]){ visited[x1][y1] = true; dfs(x1, y1); } } int x2 = x + 2*dx[dir]; int y2 = y + 2*dy[dir]; if(0 <= x2 && x2 < h && 0 <= y2 && y2 < w){ if(B[x2].charAt(y2) == B[x].charAt(y) && (int)B[x1].charAt(y1) < (int)B[x].charAt(y)){ if(!visited[x2][y2]){ visited[x2][y2] = true; dfs(x2, y2); } } } } } }