結果

問題 No.2328 Build Walls
ユーザー simansiman
提出日時 2023-05-31 13:41:56
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 679 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 11,196 KB
実行使用メモリ 26,276 KB
最終ジャッジ日時 2023-08-28 01:30:59
合計ジャッジ時間 12,278 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,140 KB
testcase_01 AC 76 ms
15,144 KB
testcase_02 AC 77 ms
15,136 KB
testcase_03 AC 76 ms
15,288 KB
testcase_04 AC 76 ms
15,144 KB
testcase_05 AC 76 ms
15,248 KB
testcase_06 AC 76 ms
15,280 KB
testcase_07 AC 76 ms
15,080 KB
testcase_08 AC 76 ms
15,056 KB
testcase_09 AC 76 ms
15,132 KB
testcase_10 AC 76 ms
15,120 KB
testcase_11 AC 76 ms
15,144 KB
testcase_12 AC 77 ms
15,124 KB
testcase_13 AC 272 ms
21,108 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 99 ms
16,160 KB
testcase_20 WA -
testcase_21 AC 202 ms
20,836 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 304 ms
26,188 KB
testcase_29 WA -
testcase_30 AC 447 ms
26,156 KB
testcase_31 AC 423 ms
26,096 KB
testcase_32 WA -
testcase_33 AC 539 ms
26,256 KB
testcase_34 AC 455 ms
26,204 KB
testcase_35 AC 554 ms
26,228 KB
testcase_36 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:31: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

H, W = gets.split.map(&:to_i)
A = (H - 2).times.map { gets.split.map(&:to_i) }

dp = Array.new(W) { Array.new(H, Float::INFINITY) }

(H - 2).times do |y|
  next if A[y][0] == -1

  dp[0][y] = A[y][0]
end

1.upto(W - 1) do |w|
  (H - 2).times do |y|
    next if A[y][w] == -1

    if y - 1 >= 0 && dp[w][y] > dp[w - 1][y - 1] + A[y][w]
      dp[w][y] = dp[w - 1][y - 1] + A[y][w]
    end

    if dp[w][y] > dp[w - 1][y] + A[y][w]
      dp[w][y] = dp[w - 1][y] + A[y][w]
    end

    if y + 1 < H - 2 && dp[w][y] > dp[w - 1][y + 1] + A[y][w]
      dp[w][y] = dp[w - 1][y + 1] + A[y][w]
    end
  end
end

if dp[W - 1].min == Float::INFINITY
  puts -1
else
  puts dp[W - 1].min
end
0