結果

問題 No.345 最小チワワ問題
コンテスト
ユーザー r6eve
提出日時 2017-08-12 12:59:56
言語 OCaml
(5.4.1)
コンパイル:
ocamlfind ocamlopt -linkpkg -package zarith,str _filename_ -o a.out
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 465 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 180 ms
コンパイル使用メモリ 22,032 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-25 04:29:28
合計ジャッジ時間 1,361 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

let () =
  let s = read_line () in
  let rec doit i w ans =
    if i = (-1) then ans
    else
      if s.[i] = 'c' then
        begin match w with
        | [] | [_] -> doit (i - 1) w ans
        | _ :: j :: _ -> doit (i - 1) w (min ans (j - i + 1))
        end
      else if s.[i] = 'w' then doit (i - 1) (i :: w) ans
      else doit (i - 1) w ans in
  let ans = doit (String.length s - 1) [] max_int in
  Printf.printf "%d\n" (if ans = max_int then (-1) else ans)
0