結果

問題 No.345 最小チワワ問題
ユーザー r6ever6eve
提出日時 2017-08-12 12:59:56
言語 OCaml
(5.2.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 465 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 20,724 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-09 00:14:34
合計ジャッジ時間 1,361 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

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