結果
問題 | No.424 立体迷路 |
ユーザー | ronpoo |
提出日時 | 2023-08-28 16:47:25 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,006 bytes |
コンパイル時間 | 322 ms |
コンパイル使用メモリ | 86,996 KB |
実行使用メモリ | 78,036 KB |
最終ジャッジ日時 | 2023-08-28 16:47:30 |
合計ジャッジ時間 | 4,422 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 91 ms
71,624 KB |
testcase_01 | AC | 91 ms
71,736 KB |
testcase_02 | AC | 89 ms
71,964 KB |
testcase_03 | AC | 88 ms
71,856 KB |
testcase_04 | AC | 94 ms
71,580 KB |
testcase_05 | AC | 94 ms
71,536 KB |
testcase_06 | AC | 92 ms
71,916 KB |
testcase_07 | AC | 91 ms
71,732 KB |
testcase_08 | AC | 92 ms
71,904 KB |
testcase_09 | AC | 91 ms
71,868 KB |
testcase_10 | AC | 93 ms
71,656 KB |
testcase_11 | AC | 90 ms
71,732 KB |
testcase_12 | AC | 92 ms
71,804 KB |
testcase_13 | AC | 92 ms
71,744 KB |
testcase_14 | AC | 94 ms
71,880 KB |
testcase_15 | AC | 95 ms
71,620 KB |
testcase_16 | AC | 90 ms
71,428 KB |
testcase_17 | AC | 92 ms
71,464 KB |
testcase_18 | AC | 91 ms
71,616 KB |
testcase_19 | AC | 91 ms
71,764 KB |
testcase_20 | AC | 92 ms
71,816 KB |
testcase_21 | AC | 91 ms
72,020 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 117 ms
78,036 KB |
testcase_25 | AC | 120 ms
77,604 KB |
ソースコード
from collections import deque h, w = map(int, input().split()) sx, sy, gx, gy = map(int, input().split()) sx, sy, gx, gy = sx-1, sy-1, gx-1, gy-1 b = [list(input()) for _ in range(h)] way = [(-1, 0), (1, 0), (0, -1), (0, 1)] dist = [[float('inf')]*w for _ in range(h)] dist[sx][sy] = 0 que = deque([(sx, sy)]) while que: x, y = que.popleft() hight = int(b[x][y]) for i, j in way: nx = x + i ny = y + j if 0 <= nx < h and 0 <= ny < w: nhight = int(b[nx][ny]) if -1 <= hight - nhight <= 1 and dist[nx][ny] == float('inf'): dist[nx][ny] = dist[x][y] + 1 que.append((nx, ny)) nx += i ny += j if 0 <= nx < h and 0 <= ny < w: nhight = int(b[nx][ny]) if hight == nhight and dist[nx][ny] == float('inf'): dist[nx][ny] = dist[x][y] + 1 que.append((nx, ny)) if dist[gx][gy] != float('inf'): print('YES') else: print('NO')