結果

問題 No.1077 Noelちゃんと星々4
ユーザー universatouniversato
提出日時 2020-06-12 22:19:11
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,673 ms / 2,000 ms
コード長 433 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 11,336 KB
実行使用メモリ 93,340 KB
最終ジャッジ日時 2023-09-06 10:37:26
合計ジャッジ時間 18,684 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,268 KB
testcase_01 AC 78 ms
15,264 KB
testcase_02 AC 1,172 ms
68,708 KB
testcase_03 AC 1,492 ms
84,516 KB
testcase_04 AC 493 ms
36,108 KB
testcase_05 AC 383 ms
30,340 KB
testcase_06 AC 615 ms
42,120 KB
testcase_07 AC 689 ms
46,440 KB
testcase_08 AC 536 ms
37,752 KB
testcase_09 AC 474 ms
34,564 KB
testcase_10 AC 1,479 ms
84,440 KB
testcase_11 AC 983 ms
60,004 KB
testcase_12 AC 818 ms
51,820 KB
testcase_13 AC 373 ms
29,816 KB
testcase_14 AC 1,443 ms
83,100 KB
testcase_15 AC 777 ms
50,904 KB
testcase_16 AC 552 ms
38,600 KB
testcase_17 AC 894 ms
55,428 KB
testcase_18 AC 1,517 ms
86,012 KB
testcase_19 AC 354 ms
29,280 KB
testcase_20 AC 81 ms
15,180 KB
testcase_21 AC 1,673 ms
93,340 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

inf = 10**4 * n
m = y.max
dp = Array.new(n+1){ [inf] * (m+1) }
dp[0][0] = 0

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