結果

問題 No.279 木の数え上げ
ユーザー r6ever6eve
提出日時 2017-08-11 16:31:18
言語 OCaml
(5.1.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 592 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 21,672 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-04-17 08:39:53
合計ジャッジ時間 1,170 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 11 ms
7,296 KB
testcase_11 AC 5 ms
5,760 KB
testcase_12 AC 8 ms
6,656 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 12 ms
7,424 KB
testcase_15 AC 10 ms
7,040 KB
testcase_16 AC 9 ms
7,040 KB
testcase_17 AC 11 ms
7,296 KB
testcase_18 AC 7 ms
6,400 KB
testcase_19 AC 11 ms
7,296 KB
testcase_20 AC 11 ms
7,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

module String = struct
  include String

  let fold_left f init str =
    let n = String.length str - 1 in
    let rec doit i acc =
      if i > n then acc
      else doit (i + 1) (f acc str.[i]) in
    doit 0 init

end

let () =
  let s = read_line () in
  let rec doit cnt (t, r, e) =
    if t < 1 || r < 1 || e < 2 then cnt
    else doit (cnt + 1) (t - 1, r - 1, e - 2) in
  String.fold_left (fun (t, r, e) c ->
    if c = 't' then t + 1, r, e
    else if c = 'r' then t, r + 1, e
    else if c = 'e' then t, r, e + 1
    else t, r, e)
    (0, 0, 0) s
  |> doit 0
  |> Printf.printf "%d\n"
0