結果

問題 No.838 Noelちゃんと星々3
ユーザー pekempeypekempey
提出日時 2019-06-15 03:08:17
言語 Crystal
(1.11.2)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 240 bytes
コンパイル時間 18,488 ms
コンパイル使用メモリ 258,684 KB
実行使用メモリ 15,672 KB
最終ジャッジ日時 2023-09-13 10:04:43
合計ジャッジ時間 19,631 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
15,660 KB
testcase_01 AC 43 ms
15,648 KB
testcase_02 AC 43 ms
15,584 KB
testcase_03 AC 43 ms
15,672 KB
testcase_04 AC 44 ms
15,616 KB
testcase_05 AC 2 ms
4,468 KB
testcase_06 AC 2 ms
4,448 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,480 KB
testcase_09 AC 3 ms
4,496 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 3 ms
4,456 KB
testcase_13 AC 2 ms
4,420 KB
testcase_14 AC 2 ms
4,392 KB
testcase_15 AC 2 ms
4,440 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,440 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,432 KB
testcase_23 AC 3 ms
4,392 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,388 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = gets.not_nil!.to_i
a = gets.not_nil!.split.map(&.to_i64).sort
dp = [10_i64**18]*(n+1)
dp[0] = 0

n.times do |i|
  dp[i+2] = [dp[i+2],dp[i]+a[i+1]-a[i]].min if i+2<=n
  dp[i+3] = [dp[i+3],dp[i]+a[i+2]-a[i]].min if i+3<=n
end

puts dp[n]
0