結果

問題 No.2328 Build Walls
ユーザー navel_tosnavel_tos
提出日時 2023-05-29 19:35:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,168 ms / 3,000 ms
コード長 978 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 91,808 KB
最終ジャッジ日時 2023-08-27 23:52:44
合計ジャッジ時間 14,064 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,064 KB
testcase_01 AC 73 ms
71,260 KB
testcase_02 AC 76 ms
70,992 KB
testcase_03 AC 77 ms
70,964 KB
testcase_04 AC 76 ms
71,248 KB
testcase_05 AC 75 ms
71,160 KB
testcase_06 AC 75 ms
71,200 KB
testcase_07 AC 76 ms
70,988 KB
testcase_08 AC 75 ms
70,816 KB
testcase_09 AC 74 ms
70,912 KB
testcase_10 AC 75 ms
71,168 KB
testcase_11 AC 74 ms
70,912 KB
testcase_12 AC 74 ms
71,152 KB
testcase_13 AC 162 ms
83,620 KB
testcase_14 AC 389 ms
81,464 KB
testcase_15 AC 306 ms
81,160 KB
testcase_16 AC 142 ms
78,456 KB
testcase_17 AC 283 ms
81,668 KB
testcase_18 AC 111 ms
77,392 KB
testcase_19 AC 84 ms
75,436 KB
testcase_20 AC 129 ms
77,796 KB
testcase_21 AC 114 ms
78,632 KB
testcase_22 AC 575 ms
85,124 KB
testcase_23 AC 903 ms
91,028 KB
testcase_24 AC 793 ms
90,540 KB
testcase_25 AC 885 ms
91,148 KB
testcase_26 AC 619 ms
89,844 KB
testcase_27 AC 789 ms
90,744 KB
testcase_28 AC 138 ms
81,768 KB
testcase_29 AC 883 ms
91,136 KB
testcase_30 AC 200 ms
88,924 KB
testcase_31 AC 192 ms
89,192 KB
testcase_32 AC 751 ms
90,596 KB
testcase_33 AC 1,168 ms
91,808 KB
testcase_34 AC 208 ms
89,036 KB
testcase_35 AC 971 ms
90,644 KB
testcase_36 AC 73 ms
71,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#MMA Contest 015 G

'''
DPみを感じる。こちらのほうが解きやすい・・・のか?
単に状態をもったDPをしたらTLEするに決まっている。

大胆予想: 左から右に王将の要領で移動する。右端にたどり着く最小コストを求めよ。
'''
import heapq as hq
import sys
f=lambda:list(map(int,input().split()))

H,W=f(); A=[[-1]*(W+1)]+[f()+[-1] for _ in range(H-2)]+[[-1]*(W+1)]
Q=[]; cost=[[10**9]*W for _ in range(H)]
for h in range(1,H-1): hq.heappush(Q,(A[h][0],h,0)) if A[h][0]>=0 else None

while Q:
    dist,h,w=hq.heappop(Q)
    if dist>cost[h][w]: continue
    if w==W-1: print(dist); sys.exit()
    cost[h][w]=dist
    for x,y in [(-1,0),(1,0),(0,-1),(0,1),(-1,-1),(-1,1),(1,-1),(1,1)]:
        if A[h+x][w+y]>=0 and cost[h+x][w+y]>dist+A[h+x][w+y]:
            cost[h+x][w+y]=dist+A[h+x][w+y]; hq.heappush(Q,(dist+A[h+x][w+y],h+x,w+y))
ans=min(cost[h][-1] for h in range(H))
print(ans) if ans<10**9 else print(-1)
0