結果

問題 No.2328 Build Walls
ユーザー sepa38sepa38
提出日時 2023-04-13 10:51:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 758 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 88,064 KB
最終ジャッジ日時 2024-04-17 15:46:52
合計ジャッジ時間 8,942 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,096 KB
testcase_01 AC 42 ms
51,840 KB
testcase_02 AC 41 ms
52,224 KB
testcase_03 AC 41 ms
51,840 KB
testcase_04 AC 41 ms
52,096 KB
testcase_05 AC 41 ms
52,096 KB
testcase_06 AC 42 ms
51,840 KB
testcase_07 AC 42 ms
52,224 KB
testcase_08 AC 39 ms
52,480 KB
testcase_09 AC 40 ms
51,840 KB
testcase_10 AC 40 ms
52,224 KB
testcase_11 AC 40 ms
52,224 KB
testcase_12 AC 41 ms
51,840 KB
testcase_13 AC 164 ms
82,304 KB
testcase_14 WA -
testcase_15 AC 153 ms
79,104 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 97 ms
76,928 KB
testcase_20 WA -
testcase_21 AC 130 ms
81,664 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 144 ms
87,040 KB
testcase_29 WA -
testcase_30 AC 203 ms
87,680 KB
testcase_31 AC 210 ms
87,680 KB
testcase_32 WA -
testcase_33 AC 1,870 ms
87,680 KB
testcase_34 AC 208 ms
87,680 KB
testcase_35 AC 310 ms
87,808 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h-2)]
inf = 1 << 30
dp = [[inf] * (h - 2) for _ in range(w)]
for i in range(h-2):
  if a[i][0] == -1:
    continue
  dp[0][i] = a[i][0]
for j in range(1, w):
  for i in range(h-2):
    if a[i][j] == -1:
      continue
    for k in range(max(0, i-1), min(h-2, i+2)):
      dp[j][i] = min(dp[j][i], dp[j-1][k]+a[i][j])
    x = a[i][j]
    for k in reversed(range(i-1)):
      if a[k+1][j] == -1:
        break
      x += a[k+1][j]
      dp[j][i] = min(dp[j][i], dp[j-1][k]+x)
    x = a[i][j]
    for k in range(i+2, h-2):
      if a[k-1][j] == -1:
        break
      x += a[k-1][j]
      dp[j][i] = min(dp[j][i], dp[j-1][k]+x)
print(min(dp[-1]) if min(dp[-1]) < inf else -1)
0