結果
問題 | No.424 立体迷路 |
ユーザー | roaris |
提出日時 | 2019-08-12 22:46:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 1,231 bytes |
コンパイル時間 | 174 ms |
コンパイル使用メモリ | 81,852 KB |
実行使用メモリ | 68,504 KB |
最終ジャッジ日時 | 2023-10-17 18:04:39 |
合計ジャッジ時間 | 2,952 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
55,652 KB |
testcase_01 | AC | 41 ms
55,652 KB |
testcase_02 | AC | 40 ms
55,652 KB |
testcase_03 | AC | 40 ms
55,652 KB |
testcase_04 | AC | 41 ms
55,652 KB |
testcase_05 | AC | 40 ms
55,652 KB |
testcase_06 | AC | 40 ms
55,652 KB |
testcase_07 | AC | 41 ms
55,652 KB |
testcase_08 | AC | 40 ms
55,652 KB |
testcase_09 | AC | 41 ms
55,652 KB |
testcase_10 | AC | 40 ms
55,652 KB |
testcase_11 | AC | 40 ms
55,652 KB |
testcase_12 | AC | 41 ms
55,652 KB |
testcase_13 | AC | 41 ms
55,652 KB |
testcase_14 | AC | 41 ms
55,652 KB |
testcase_15 | AC | 40 ms
55,652 KB |
testcase_16 | AC | 41 ms
55,652 KB |
testcase_17 | AC | 45 ms
61,660 KB |
testcase_18 | AC | 45 ms
61,660 KB |
testcase_19 | AC | 46 ms
61,660 KB |
testcase_20 | AC | 45 ms
61,660 KB |
testcase_21 | AC | 41 ms
55,652 KB |
testcase_22 | AC | 41 ms
55,652 KB |
testcase_23 | AC | 40 ms
55,652 KB |
testcase_24 | AC | 61 ms
68,504 KB |
testcase_25 | AC | 61 ms
68,504 KB |
ソースコード
from collections import deque def bfs(sx, sy): queue = deque([]) queue.append((sx, sy)) visited = [[-1 for _ in range(w)] for _ in range(h)] visited[sx][sy] = 1 while len(queue) > 0: cx, cy = queue.popleft() for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: nx, ny = cx + dx, cy + dy if 0 <= nx < h and 0 <= ny < w: if abs(S[cx][cy] - S[nx][ny]) <= 1 and visited[nx][ny] == -1: visited[nx][ny] = 1 queue.append((nx, ny)) for dx, dy in [(-2, 0), (2, 0), (0, -2), (0, 2)]: nx, ny = cx + dx, cy + dy if 0 <= nx < h and 0 <= ny < w: mx, my = (nx + cx) // 2, (ny + cy) // 2 if S[cx][cy] == S[nx][ny] and S[cx][cy] > S[mx][my] and visited[nx][ny] == -1: visited[nx][ny] = 1 queue.append((nx, ny)) return visited h, w = map(int, input().split()) sx, sy, gx, gy = map(int, input().split()) S = [list(map(int, list(input()))) for _ in range(h)] visited = bfs(sx-1, sy-1) if visited[gx-1][gy-1] == 1: print('YES') else: print('NO')