結果
問題 |
No.971 いたずらっ子
|
ユーザー |
![]() |
提出日時 | 2020-01-29 20:14:58 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,464 bytes |
コンパイル時間 | 246 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 765,644 KB |
最終ジャッジ日時 | 2024-09-16 02:06:14 |
合計ジャッジ時間 | 7,479 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | MLE * 1 -- * 20 |
ソースコード
from collections import deque H,W = map(int, input().split()) L = [input() for _ in range(H)] inf = 10**15 dist = [[inf]*W for _ in range(H)] q = deque() q.append((0, 0, 0, 0)) while q: temp = q.popleft() i = temp[0] j = temp[1] d = temp[2] sub_d = temp[3] if i > 0: if L[i-1][j] == "." and dist[i-1][j] > d+1: dist[i-1][j] = d+1 q.append((i-1, j, d+1, sub_d+1)) elif L[i-1][j] == "k" and dist[i-1][j] > d+2+sub_d: dist[i-1][j] = d+2+sub_d q.append((i-1, j, d+2+sub_d, sub_d+1)) if i < H-1: if L[i+1][j] == "." and dist[i+1][j] > d+1: dist[i+1][j] = d+1 q.append((i+1, j, d+1, sub_d+1)) elif L[i+1][j] == "k" and dist[i+1][j] > d+2+sub_d: dist[i+1][j] = d+2+sub_d q.append((i+1, j, d+2+sub_d, sub_d+1)) if j > 0: if L[i][j-1] == "." and dist[i][j-1] > d+1: dist[i][j-1] = d+1 q.append((i, j-1, d+1, sub_d+1)) elif L[i][j-1] == "k" and dist[i][j-1] > d+2+sub_d: dist[i][j-1] = d+2+sub_d q.append((i, j-1, d+2+sub_d, sub_d+1)) if j < W-1: if L[i][j+1] == "." and dist[i][j+1] > d+1: dist[i][j+1] = d+1 q.append((i, j+1, d+1, sub_d+1)) elif L[i][j+1] == "k" and dist[i][j+1] > d+2+sub_d: dist[i][j+1] = d+2+sub_d q.append((i, j+1, d+2+sub_d, sub_d+1)) print(dist[H-1][W-1])