結果

問題 No.279 木の数え上げ
ユーザー ichibanshiboriichibanshibori
提出日時 2016-12-12 05:05:45
言語 OCaml
(5.1.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 564 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 19,564 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-04-17 08:35:40
合計ジャッジ時間 1,053 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

let solve s =
  let lstr = String.length s in

  let rec solve' idx result =
    if idx >= lstr then result
    else
      let t_cnt, r_cnt, e_cnt = result in
      let t_cnt, r_cnt, e_cnt =
        t_cnt + (if s.[idx] = 't' then 1 else 0),
        r_cnt + (if s.[idx] = 'r' then 1 else 0),
        e_cnt + (if s.[idx] = 'e' then 1 else 0)
      in
      solve' (idx + 1) (t_cnt, r_cnt, e_cnt)
  in
  let t_cnt, r_cnt, e_cnt = solve' 0 (0, 0, 0) in
  min t_cnt (min r_cnt (e_cnt / 2))

let () =
  let s = read_line () in
  solve s |> string_of_int |> print_endline
0