結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-15 21:28:02 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 968 bytes |
| コンパイル時間 | 100 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 91,976 KB |
| 最終ジャッジ日時 | 2024-10-01 19:02:49 |
| 合計ジャッジ時間 | 7,754 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 20 |
ソースコード
INF = 10 ** 7
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from collections import deque
def main():
h,w = map(int,input().split())
grid = [list(input()) for _ in range(h)]
q = deque()
q.append((0,0))
dist = [[INF] * w for _ in range(h)]
dist[0][0] = 0
while q:
i,j = q.popleft()
for k in range(4):
y = i + dy[k]
x = j + dx[k]
if y < 0 or y >= h:
continue
if x < 0 or x >= w:
continue
if grid[y][x] == 'k':
if dist[y][x] > dist[i][j] + 1 + y + x:
dist[y][x] = dist[i][j] + 1 + y + x
q.append((y,x))
else:
if dist[y][x] > dist[i][j] + 1:
dist[y][x] = dist[i][j] + 1
q.append((y,x))
print(dist[-1][-1])
if __name__ == '__main__':
main()