結果
問題 | No.2096 Rage With Our Friends |
ユーザー | 👑 AngrySadEight |
提出日時 | 2022-09-14 01:07:26 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
(最新)
WA
(最初)
|
実行時間 | - |
コード長 | 2,463 bytes |
コンパイル時間 | 324 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 905,788 KB |
最終ジャッジ日時 | 2024-12-15 12:21:36 |
合計ジャッジ時間 | 31,750 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | MLE | - |
testcase_01 | AC | 47 ms
56,528 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 46 ms
56,148 KB |
testcase_07 | WA | - |
testcase_08 | AC | 47 ms
56,552 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 301 ms
176,940 KB |
testcase_13 | WA | - |
testcase_14 | TLE | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | TLE | - |
testcase_18 | WA | - |
testcase_19 | AC | 48 ms
57,256 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | TLE | - |
testcase_23 | WA | - |
testcase_24 | AC | 546 ms
153,564 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | MLE | - |
ソースコード
from collections import deque from xml.dom import HierarchyRequestErr H, W = map(int, input().split()) sx, sy, gx, gy = map(int, input().split()) sx -= 1 sy -= 1 gx -= 1 gy -= 1 S = [] for i in range(H): s = str(input()) S.append(s) calc_highest_x = [H - 1 for _ in range(W)] highest_x = [[H - 1 for _ in range(W)] for _ in range(H)] for i in reversed(range(H - 1)): for j in range(W): if S[i][j] == '#': calc_highest_x[j] = i highest_x[i][j] = calc_highest_x[j] INF = 1 << 24 isvisited = [[False for _ in range(W)] for _ in range(H)] dist = [[INF for _ in range(W)] for _ in range(H)] dq = deque() dq.appendleft([sx, sy]) dist[sx][sy] = 0 while len(dq): px, py = dq.popleft() if isvisited[px][py]: continue isvisited[px][py] = True if py - 1 >= 0: next_x = max(0, px - 1) next_x = highest_x[next_x][py - 1] dq.appendleft([next_x, py - 1]) dist[next_x][py - 1] = min(dist[next_x][py - 1], dist[px][py]) if py + 1 < W: next_x = max(0, px - 1) next_x = highest_x[next_x][py + 1] dq.appendleft([next_x, py + 1]) dist[next_x][py + 1] = min(dist[next_x][py + 1], dist[px][py]) if py - 2 >= 0: next_x = max(0, px - 1) next_x = highest_x[next_x][py - 2] dq.append([next_x, py - 2]) dist[next_x][py - 2] = min(dist[next_x][py - 2], dist[px][py] + 1) if py - 2 >= 0: diffs_x = highest_x[px][py - 1] - px next_x = highest_x[px][py - 1] - 1 - diffs_x // 2 next_x = highest_x[max(0, next_x)][py - 2] dq.appendleft([next_x, py - 2]) dist[next_x][py - 2] = min(dist[next_x][py - 2], dist[px][py]) if py + 2 < W: next_x = max(0, px - 1) next_x = highest_x[next_x][py + 2] dq.append([next_x, py + 2]) dist[next_x][py + 2] = min(dist[next_x][py + 2], dist[px][py] + 1) if py + 2 < W: diffs_x = highest_x[px][py + 1] - px next_x = highest_x[px][py + 1] - 1 - diffs_x // 2 next_x = highest_x[max(0, next_x)][py + 2] dq.appendleft([next_x, py + 2]) dist[next_x][py + 2] = min(dist[next_x][py + 2], dist[px][py]) if 0 <= py < W: next_x = max(0, px - 1) next_x = highest_x[next_x][py] dq.append([next_x, py]) dist[next_x][py] = min(dist[next_x][py], dist[px][py] + 1) if dist[gx][gy] == INF: print(-1) else: print(dist[gx][gy])