結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
convexineq
|
| 提出日時 | 2020-01-17 22:01:26 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,406 bytes |
| コンパイル時間 | 113 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 150,568 KB |
| 最終ジャッジ日時 | 2024-06-25 20:05:14 |
| 合計ジャッジ時間 | 6,886 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)]
b[0][0] = 0
INF = 10**9
dp = [0]+[INF]*(w-1)
for bi in b:
for j, bij in enumerate(bi):
if j:
dp[j] = min(dp[j],dp[j-1]) + bij
else:
dp[j] += bij
print(dp[-1])
convexineq