結果

問題 No.2328 Build Walls
ユーザー pありpあり
提出日時 2023-05-28 14:50:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,228 ms / 3,000 ms
コード長 930 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 92,956 KB
最終ジャッジ日時 2023-08-27 10:41:43
合計ジャッジ時間 14,591 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,576 KB
testcase_01 AC 86 ms
71,848 KB
testcase_02 AC 85 ms
71,908 KB
testcase_03 AC 84 ms
71,432 KB
testcase_04 AC 86 ms
71,820 KB
testcase_05 AC 85 ms
71,724 KB
testcase_06 AC 89 ms
71,816 KB
testcase_07 AC 87 ms
71,736 KB
testcase_08 AC 86 ms
71,768 KB
testcase_09 AC 85 ms
71,560 KB
testcase_10 AC 85 ms
71,612 KB
testcase_11 AC 87 ms
71,408 KB
testcase_12 AC 82 ms
71,692 KB
testcase_13 AC 186 ms
84,624 KB
testcase_14 AC 404 ms
83,680 KB
testcase_15 AC 325 ms
82,180 KB
testcase_16 AC 162 ms
79,500 KB
testcase_17 AC 308 ms
83,084 KB
testcase_18 AC 144 ms
78,656 KB
testcase_19 AC 109 ms
78,156 KB
testcase_20 AC 149 ms
79,208 KB
testcase_21 AC 151 ms
84,112 KB
testcase_22 AC 582 ms
86,520 KB
testcase_23 AC 912 ms
92,228 KB
testcase_24 AC 834 ms
92,136 KB
testcase_25 AC 884 ms
92,560 KB
testcase_26 AC 657 ms
90,716 KB
testcase_27 AC 772 ms
91,980 KB
testcase_28 AC 170 ms
89,408 KB
testcase_29 AC 889 ms
92,268 KB
testcase_30 AC 209 ms
90,084 KB
testcase_31 AC 204 ms
90,140 KB
testcase_32 AC 784 ms
91,824 KB
testcase_33 AC 1,228 ms
92,956 KB
testcase_34 AC 230 ms
90,420 KB
testcase_35 AC 1,041 ms
92,064 KB
testcase_36 AC 85 ms
71,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import bisect
import heapq

h,w = map(int, input().split())
h-=2

a = []
M = 10**18

for _ in range(h):
  aa = list(map(int, input().split()))
  for i in range(w):
    if(aa[i]==-1):
      aa[i] = M
  a.append(aa)
   
    
hh = []
weight = [[M for _ in range(w)] for _ in range(h)]
for i in range(h):
  hh.append((a[i][0], 0, i))
  weight[i][0] =  a[i][0]
  
heapq.heapify(hh)



while(hh):
  
  ww, x, y = heapq.heappop(hh)
  
  if(weight[y][x] < ww):
    continue
    
  for dy in  range(-1,2):
    yy = y+dy
    if(yy<0 or h<=yy):
      continue
    for dx in range(-1,2):
      xx = x+dx
      if(xx<0 or w<=xx):
        continue
        
      w_new = ww+a[yy][xx]
      if(weight[yy][xx] > w_new):
        weight[yy][xx] = w_new
        heapq.heappush(hh, (w_new, xx, yy))
        
ans = M
for i in range(h):
  ans = min(ans, weight[i][-1])
  
if(ans >= M):
  print(-1)
else:
  print(ans)
  


0