結果

問題 No.178 美しいWhitespace (1)
ユーザー ichibanshiboriichibanshibori
提出日時 2016-10-07 00:22:41
言語 OCaml
(5.1.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 610 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 21,508 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 08:34:25
合計ジャッジ時間 1,093 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,948 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 3 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 3 ms
6,944 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let solve n abArr =
  let a4bArr = Array.map (fun (a, b) -> a + 4 * b) abArr in
  Array.sort compare a4bArr;
  let maxAb = a4bArr.(n - 1) in
  let rec solve' idx result =
    if idx >= n then result
    else let c2 = maxAb - a4bArr.(idx) in
         if c2 mod 2 <> 0 then -1
         else solve' (idx + 1) (c2 / 2 + result)
  in
  solve' 0 0

let () =
  let n = read_int () in
  let abArr = Array.make n (0, 0) in
  let rec readAb i =
    if i < n then (Scanf.scanf "%d %d\n" (fun a b -> abArr.(i) <- (a, b));
                   readAb (i + 1))
  in
  readAb 0;
  solve n abArr |> print_int;
  print_newline ()
0