結果

問題 No.971 いたずらっ子
ユーザー convexineqconvexineq
提出日時 2020-01-17 22:01:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,406 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 11,064 KB
実行使用メモリ 168,656 KB
最終ジャッジ日時 2023-09-08 02:56:21
合計ジャッジ時間 6,747 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 AC 1,952 ms
36,288 KB
testcase_07 AC 37 ms
8,800 KB
testcase_08 AC 757 ms
50,088 KB
testcase_09 AC 722 ms
48,436 KB
testcase_10 AC 37 ms
8,488 KB
testcase_11 AC 16 ms
8,292 KB
testcase_12 AC 17 ms
8,244 KB
testcase_13 AC 17 ms
8,508 KB
testcase_14 AC 20 ms
8,480 KB
testcase_15 AC 18 ms
8,396 KB
testcase_16 AC 16 ms
8,412 KB
testcase_17 AC 16 ms
8,224 KB
testcase_18 AC 16 ms
8,288 KB
testcase_19 AC 17 ms
8,284 KB
testcase_20 AC 16 ms
8,288 KB
testcase_21 AC 16 ms
8,412 KB
testcase_22 AC 16 ms
8,224 KB
testcase_23 AC 16 ms
8,104 KB
testcase_24 AC 16 ms
8,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])






0