結果

問題 No.112 ややこしい鶴亀算
ユーザー ichibanshibori
提出日時 2017-04-30 23:22:02
言語 OCaml
(5.2.1)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 739 bytes
コンパイル時間 459 ms
コンパイル使用メモリ 20,992 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-08 23:59:15
合計ジャッジ時間 1,673 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

let list_max_min lst =
  let rec list_max_min_by' lst cur_max cur_min =
    match lst with
    | [] -> (cur_max, cur_min)
    | x::xs -> list_max_min_by' xs (max cur_max x) (min cur_min x)
  in
  match lst with
  | [] -> failwith "list is empty"
  | [x] -> (x, x)
  | x::xs -> list_max_min_by' xs x x


let solve n a_lst =
  let max_l, min_l = list_max_min a_lst in
  if max_l = min_l then
  (
    if max_l / (n - 1) = 2 then (n, 0) else (0, n)
  )
  else let y = ((max_l + 2) - 2 * n) / 2 in (n - y, y)

let () =
  let n = read_line () |> int_of_string
  and a_lst = read_line ()
              |> Str.split (Str.regexp_string " ")
              |> List.map int_of_string
  in
  solve n a_lst
  |> fun (t, k) -> Printf.printf "%d %d\n" t k
0