結果

問題 No.2328 Build Walls
ユーザー navel_tosnavel_tos
提出日時 2023-05-29 19:35:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,167 ms / 3,000 ms
コード長 978 bytes
コンパイル時間 525 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 90,292 KB
最終ジャッジ日時 2024-06-08 19:24:45
合計ジャッジ時間 12,504 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,352 KB
testcase_01 AC 37 ms
52,352 KB
testcase_02 AC 37 ms
52,352 KB
testcase_03 AC 39 ms
52,608 KB
testcase_04 AC 40 ms
52,352 KB
testcase_05 AC 38 ms
52,352 KB
testcase_06 AC 40 ms
52,736 KB
testcase_07 AC 41 ms
52,608 KB
testcase_08 AC 40 ms
52,864 KB
testcase_09 AC 40 ms
52,608 KB
testcase_10 AC 39 ms
52,608 KB
testcase_11 AC 38 ms
52,992 KB
testcase_12 AC 40 ms
52,224 KB
testcase_13 AC 127 ms
82,432 KB
testcase_14 AC 360 ms
80,640 KB
testcase_15 AC 272 ms
79,804 KB
testcase_16 AC 113 ms
76,928 KB
testcase_17 AC 256 ms
80,316 KB
testcase_18 AC 77 ms
74,884 KB
testcase_19 AC 47 ms
67,712 KB
testcase_20 AC 94 ms
76,544 KB
testcase_21 AC 82 ms
77,952 KB
testcase_22 AC 544 ms
83,456 KB
testcase_23 AC 875 ms
90,136 KB
testcase_24 AC 772 ms
89,024 KB
testcase_25 AC 864 ms
89,644 KB
testcase_26 AC 581 ms
88,472 KB
testcase_27 AC 748 ms
88,580 KB
testcase_28 AC 114 ms
81,792 KB
testcase_29 AC 859 ms
89,388 KB
testcase_30 AC 161 ms
87,552 KB
testcase_31 AC 148 ms
82,816 KB
testcase_32 AC 714 ms
88,720 KB
testcase_33 AC 1,167 ms
90,292 KB
testcase_34 AC 172 ms
87,552 KB
testcase_35 AC 944 ms
89,560 KB
testcase_36 AC 41 ms
52,992 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