結果

問題 No.2095 High Rise
ユーザー simansiman
提出日時 2022-10-10 19:56:35
言語 Ruby
(3.3.0)
結果
AC  
実行時間 625 ms / 2,000 ms
コード長 505 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 11,320 KB
実行使用メモリ 33,912 KB
最終ジャッジ日時 2023-09-06 22:40:59
合計ジャッジ時間 7,715 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,128 KB
testcase_01 AC 78 ms
15,200 KB
testcase_02 AC 80 ms
15,140 KB
testcase_03 AC 78 ms
15,040 KB
testcase_04 AC 77 ms
15,308 KB
testcase_05 AC 77 ms
15,036 KB
testcase_06 AC 78 ms
15,240 KB
testcase_07 AC 77 ms
15,152 KB
testcase_08 AC 77 ms
15,268 KB
testcase_09 AC 77 ms
15,168 KB
testcase_10 AC 77 ms
15,172 KB
testcase_11 AC 78 ms
15,140 KB
testcase_12 AC 82 ms
15,432 KB
testcase_13 AC 81 ms
15,296 KB
testcase_14 AC 82 ms
15,240 KB
testcase_15 AC 80 ms
15,216 KB
testcase_16 AC 81 ms
15,140 KB
testcase_17 AC 140 ms
17,364 KB
testcase_18 AC 120 ms
16,652 KB
testcase_19 AC 91 ms
15,460 KB
testcase_20 AC 148 ms
17,308 KB
testcase_21 AC 208 ms
19,592 KB
testcase_22 AC 625 ms
33,860 KB
testcase_23 AC 621 ms
33,772 KB
testcase_24 AC 620 ms
33,712 KB
testcase_25 AC 621 ms
33,740 KB
testcase_26 AC 618 ms
33,912 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
A = N.times.map { gets.split.map(&:to_i) }

if N == 1
  puts 0
  exit
end

dp = Array.new(N) { Array.new(M, Float::INFINITY) }

N.times do |i|
  if i == 0
    M.times do |j|
      dp[i][j] = A[i][j]
    end
  else
    min_v = Float::INFINITY

    M.times do |j|
      dp[i][j] = dp[i - 1][j] + A[i][j]
      min_v = dp[i][j] if min_v > dp[i][j]
    end

    M.times do |j|
      nv = min_v + A[i][j]
      dp[i][j] = nv if dp[i][j] > nv
    end
  end
end

puts dp[N - 1].min
0