結果

問題 No.35 タイパー高橋
ユーザー ichibanshiboriichibanshibori
提出日時 2017-05-01 00:09:28
言語 OCaml
(5.1.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 793 bytes
コンパイル時間 54 ms
コンパイル使用メモリ 16,896 KB
最終ジャッジ日時 2024-04-27 02:25:24
合計ジャッジ時間 377 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
File "Main.ml", line 2, characters 2-13:
2 |   Stream.from (fun _ -> try Some (f (Stream.next stream))
      ^^^^^^^^^^^
Error: Unbound module Stream

ソースコード

diff #

let stream_map f stream =
  Stream.from (fun _ -> try Some (f (Stream.next stream))
                        with Stream.Failure -> None)

let stream_fold f init st =
  let result = ref init in
  Stream.iter (fun x -> result := f !result x) st;
  !result


let solve ts_st =
  ts_st
  |> stream_map (fun (t, s) ->
    let len_s = String.length s
    and len_t = t * 12 / 1000 in
    let r = if len_s <= len_t then len_s else len_t in
    (r, len_s - r))
  |> stream_fold (fun (x1, y1) (x2, y2) -> (x1 + x2, y1 + y2)) (0, 0)

let () =
  let n = read_line () |> int_of_string in
  let ts_st = Stream.from (fun i ->
    if i >= n then None
    else read_line ()
         |> fun l -> Scanf.sscanf l "%d %s" (fun t s -> Some(t, s))
  ) in
  solve ts_st
  |> fun (x, y) -> Printf.printf "%d %d\n" x y
0