結果
問題 | No.2328 Build Walls |
ユーザー | とりゐ |
提出日時 | 2023-05-28 14:11:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,335 ms / 3,000 ms |
コード長 | 1,086 bytes |
コンパイル時間 | 858 ms |
コンパイル使用メモリ | 87,236 KB |
実行使用メモリ | 97,788 KB |
最終ジャッジ日時 | 2023-08-27 09:11:17 |
合計ジャッジ時間 | 16,289 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
71,412 KB |
testcase_01 | AC | 76 ms
71,396 KB |
testcase_02 | AC | 77 ms
71,624 KB |
testcase_03 | AC | 77 ms
71,432 KB |
testcase_04 | AC | 78 ms
71,428 KB |
testcase_05 | AC | 77 ms
71,380 KB |
testcase_06 | AC | 78 ms
71,408 KB |
testcase_07 | AC | 78 ms
71,304 KB |
testcase_08 | AC | 77 ms
71,420 KB |
testcase_09 | AC | 76 ms
71,532 KB |
testcase_10 | AC | 76 ms
71,376 KB |
testcase_11 | AC | 76 ms
71,456 KB |
testcase_12 | AC | 76 ms
71,332 KB |
testcase_13 | AC | 187 ms
86,596 KB |
testcase_14 | AC | 461 ms
83,988 KB |
testcase_15 | AC | 351 ms
83,276 KB |
testcase_16 | AC | 169 ms
79,548 KB |
testcase_17 | AC | 330 ms
83,820 KB |
testcase_18 | AC | 136 ms
78,432 KB |
testcase_19 | AC | 88 ms
75,836 KB |
testcase_20 | AC | 150 ms
79,028 KB |
testcase_21 | AC | 119 ms
79,700 KB |
testcase_22 | AC | 655 ms
87,604 KB |
testcase_23 | AC | 1,016 ms
96,784 KB |
testcase_24 | AC | 973 ms
96,260 KB |
testcase_25 | AC | 1,048 ms
96,604 KB |
testcase_26 | AC | 746 ms
95,632 KB |
testcase_27 | AC | 925 ms
95,808 KB |
testcase_28 | AC | 150 ms
89,608 KB |
testcase_29 | AC | 1,105 ms
96,636 KB |
testcase_30 | AC | 223 ms
94,236 KB |
testcase_31 | AC | 210 ms
94,144 KB |
testcase_32 | AC | 909 ms
95,756 KB |
testcase_33 | AC | 1,335 ms
97,788 KB |
testcase_34 | AC | 237 ms
94,092 KB |
testcase_35 | AC | 1,154 ms
96,068 KB |
testcase_36 | AC | 78 ms
71,160 KB |
ソースコード
h,w=map(int,input().split()) h-=2 a=[list(map(int,input().split())) for i in range(h)] from heapq import heappush,heappop INF=10**18 def dijkstra(start,n): dist=[INF]*n hq=[(0,start)] dist[start]=0 seen=[False]*n while hq: w,v=heappop(hq) if dist[v]<w: continue seen[v]=True for to,cost in edge[v]: if seen[to]==False and dist[v]+cost<dist[to]: dist[to]=dist[v]+cost heappush(hq,(dist[to],to)) return dist inf=1<<60 dist=[[inf]*w for i in range(h)] seen=[[False]*w for i in range(h)] hq=[] for i in range(h): if a[i][0]!=-1: heappush(hq,(a[i][0],i,0)) dist[i][0]=a[i][0] while hq: _,x,y=heappop(hq) if seen[x][y]: continue seen[x][y]=True for dx in range(-1,2): for dy in range(-1,2): nx,ny=x+dx,y+dy if 0<=nx<h and 0<=ny<w: if seen[nx][ny]==False and a[nx][ny]!=-1 and dist[x][y]+a[nx][ny]<dist[nx][ny]: dist[nx][ny]=dist[x][y]+a[nx][ny] heappush(hq,(dist[nx][ny],nx,ny)) ans=inf for i in range(h): ans=min(ans,dist[i][w-1]) if ans==inf: ans=-1 print(ans)