結果

問題 No.29 パワーアップ
ユーザー ichibanshiboriichibanshibori
提出日時 2016-10-26 14:55:01
言語 OCaml
(5.1.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 874 bytes
コンパイル時間 44 ms
コンパイル使用メモリ 17,280 KB
最終ジャッジ日時 2024-04-17 08:35:13
合計ジャッジ時間 430 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
File "Main.ml", line 14, characters 2-13:
14 |   Stream.iter (fun (a, b, c) ->
       ^^^^^^^^^^^
Error: Unbound module Stream

ソースコード

diff #

let solve arr =
  let rec solve' idx rem result =
    if idx >= 10 then result + rem / 4
    else
      let next_rem, next_result =
        rem + arr.(idx) mod 2, result + arr.(idx) / 2
      in
      solve' (idx + 1) next_rem next_result
  in
  solve' 0 0 0

let read_abc in_seq =
  let arr = Array.make 10 0 in
  Stream.iter (fun (a, b, c) ->
    arr.(a) <- arr.(a) + 1;
    arr.(b) <- arr.(b) + 1;
    arr.(c) <- arr.(c) + 1) in_seq;
  arr

let () =
  let n = read_line () |> int_of_string in
  let in_seq = Stream.from (fun i ->
    if i >= n then None
    else
      read_line () |>
      Str.split (Str.regexp_string " ") |>
      List.map int_of_string |>
      fun lst -> Some (List.nth lst 0 - 1,
                       List.nth lst 1 - 1,
                       List.nth lst 2 - 1))
  in
  let arr = read_abc in_seq in
  solve arr |> string_of_int |> print_endline
0