結果

問題 No.2328 Build Walls
ユーザー navel_tosnavel_tos
提出日時 2023-05-29 19:31:03
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 902 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 129,320 KB
最終ジャッジ日時 2023-08-27 23:51:38
合計ジャッジ時間 23,464 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,272 KB
testcase_01 AC 73 ms
71,404 KB
testcase_02 AC 72 ms
71,132 KB
testcase_03 AC 73 ms
71,476 KB
testcase_04 AC 73 ms
71,500 KB
testcase_05 AC 73 ms
71,356 KB
testcase_06 AC 73 ms
71,260 KB
testcase_07 AC 75 ms
71,256 KB
testcase_08 AC 73 ms
71,412 KB
testcase_09 AC 72 ms
71,236 KB
testcase_10 AC 74 ms
71,340 KB
testcase_11 AC 73 ms
71,260 KB
testcase_12 AC 73 ms
71,464 KB
testcase_13 AC 187 ms
84,316 KB
testcase_14 AC 1,101 ms
96,868 KB
testcase_15 AC 563 ms
84,376 KB
testcase_16 AC 174 ms
79,284 KB
testcase_17 AC 397 ms
82,756 KB
testcase_18 AC 137 ms
78,488 KB
testcase_19 AC 83 ms
75,732 KB
testcase_20 AC 171 ms
78,596 KB
testcase_21 AC 110 ms
78,932 KB
testcase_22 AC 1,962 ms
128,496 KB
testcase_23 AC 1,828 ms
104,316 KB
testcase_24 AC 1,568 ms
100,220 KB
testcase_25 AC 1,774 ms
102,664 KB
testcase_26 AC 984 ms
92,736 KB
testcase_27 AC 1,401 ms
96,256 KB
testcase_28 AC 134 ms
82,144 KB
testcase_29 AC 1,896 ms
103,668 KB
testcase_30 AC 214 ms
89,580 KB
testcase_31 AC 188 ms
89,560 KB
testcase_32 AC 1,349 ms
95,912 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#MMA Contest 015 G

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

大胆予想: 左から右に王将の要領で移動する。右端にたどり着く最小コストを求めよ。
'''
import heapq as hq
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=[[2*10**18]*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
    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:
            if 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<2*10**18 else print(-1)
0