結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
convexineq
|
| 提出日時 | 2020-01-17 21:48:09 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,241 bytes |
| コンパイル時間 | 286 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 177,408 KB |
| 最終ジャッジ日時 | 2024-06-25 19:28:12 |
| 合計ジャッジ時間 | 7,052 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 20 |
ソースコード
def dijkstra_grid(g,sx,sy):
from heapq import heappush,heappop
h,w = len(g),len(g[0])
dx4=[0, 1, 0,-1]
dy4=[1, 0,-1, 0]
INF = 10**9
dist = [[INF]*w for _ in range(h)] #startからの最短距離
dist[sx][sy] = 0
q = [(0,sx,sy)] #(そこまでの距離、点)
while q:
dv,vx,vy = heappop(q)
if dist[vx][vy] < dv: continue
for i in range(4):
nx = vx + dx4[i]
ny = vy + dy4[i]
if nx < 0 or nx>=h or ny <0 or ny>=w: continue #範囲外?
#if b[nx][ny] == "#": continue #壁?
cost = b[nx][ny]
if dv + cost < dist[nx][ny]:
dist[nx][ny] = dv + cost
heappush(q, (dv + cost, nx,ny))
return dist
#######################################################
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
#n,m,*d= [int(i) for i in read().split()]
#a,t,k = [int(i) for i in readline().split()]
h,w = [int(i) for i in readline().split()]
bbb = read().split()
b = [[i+j+1 if bij=="k" else 1 for j,bij in enumerate(bi)] for i,bi in enumerate(bbb)]
dist = dijkstra_grid(b,0,0)
print(dist[-1][-1])
convexineq