結果
問題 |
No.2328 Build Walls
|
ユーザー |
![]() |
提出日時 | 2023-05-29 19:31:58 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 896 bytes |
コンパイル時間 | 252 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 127,452 KB |
最終ジャッジ日時 | 2024-12-28 10:14:46 |
合計ジャッジ時間 | 27,234 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 TLE * 1 |
ソースコード
#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=[[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 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<10**9 else print(-1)