結果

問題 No.838 Noelちゃんと星々3
ユーザー pekempeypekempey
提出日時 2019-06-23 23:44:59
言語 OCaml
(5.1.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 424 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 19,712 KB
実行使用メモリ 16,484 KB
最終ジャッジ日時 2024-04-17 08:48:05
合計ジャッジ時間 1,888 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
16,460 KB
testcase_01 AC 70 ms
16,484 KB
testcase_02 AC 68 ms
16,484 KB
testcase_03 AC 73 ms
16,452 KB
testcase_04 AC 71 ms
16,484 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let n = read_int();;
let a = read_line() |> String.split_on_char ' ' |> List.map int_of_string |> List.sort compare |> Array.of_list;;
let inf = 1000000000;;
let dp = Array.make (n+1) inf;;
dp.(0) <- 0;;
for i = 0 to n do
  if i + 2 <= n then
    dp.(i+2) <- min dp.(i+2) (dp.(i) + a.(i+1) - a.(i));
  if i + 3 <= n then
    dp.(i+3) <- min dp.(i+3) (dp.(i) + a.(i+2) - a.(i));
done;;
print_int dp.(n);;
print_newline ();;

0