結果

問題 No.1077 Noelちゃんと星々4
ユーザー universatouniversato
提出日時 2020-06-12 23:32:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,169 ms / 2,000 ms
コード長 364 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 11,252 KB
実行使用メモリ 15,336 KB
最終ジャッジ日時 2023-09-06 11:27:41
合計ジャッジ時間 14,273 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
15,104 KB
testcase_01 AC 72 ms
15,096 KB
testcase_02 AC 834 ms
15,156 KB
testcase_03 AC 1,096 ms
15,196 KB
testcase_04 AC 378 ms
15,220 KB
testcase_05 AC 281 ms
15,280 KB
testcase_06 AC 446 ms
15,272 KB
testcase_07 AC 519 ms
15,044 KB
testcase_08 AC 403 ms
15,276 KB
testcase_09 AC 362 ms
15,144 KB
testcase_10 AC 1,065 ms
15,060 KB
testcase_11 AC 703 ms
15,116 KB
testcase_12 AC 580 ms
15,140 KB
testcase_13 AC 285 ms
15,140 KB
testcase_14 AC 1,048 ms
15,276 KB
testcase_15 AC 555 ms
15,336 KB
testcase_16 AC 398 ms
15,280 KB
testcase_17 AC 630 ms
15,156 KB
testcase_18 AC 1,087 ms
15,260 KB
testcase_19 AC 274 ms
15,092 KB
testcase_20 AC 76 ms
15,084 KB
testcase_21 AC 1,169 ms
15,308 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_s.to_i
y = gets.to_s.split.map{|t| t.to_i }

inf = 10**4 * n
dp = [inf] * (y.max + 1)
dp[0] = 0

m = 0
y.each_with_index do |t, i|
  
  m = t if m < t
  
  dp[0] = dp[0] + t
  
  1.upto(t) do |j|
    dp[j] = [dp[j] + t - j, dp[j-1] - 1 ].min
  end
  
  (t+1).upto(m) do |j|
    dp[j] = [dp[j] + j - t, dp[j-1] + 1 ].min
  end
end

ans = dp.min
puts ans
0