結果
| 問題 | No.345 最小チワワ問題 |
| コンテスト | |
| ユーザー |
r6eve
|
| 提出日時 | 2017-08-12 10:01:06 |
| 言語 | OCaml (5.4.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 701 bytes |
| 記録 | |
| コンパイル時間 | 298 ms |
| コンパイル使用メモリ | 20,852 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-09 00:14:21 |
| 合計ジャッジ時間 | 1,494 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 WA * 14 |
ソースコード
let () =
let s = read_line () in
let n = String.length s in
let rec doit i c w =
if i = n then c, w
else begin
if s.[i] = 'c' then
if c <> (-1) then doit (i + 1) c w
else doit (i + 1) i w
else if s.[i] = 'w' then
if c = (-1) then doit (i + 1) c w
else
match w with
| [] -> doit (i + 1) c (i :: w)
| [_] -> c, i :: w
| _ -> assert false
else doit (i + 1) c w
end in
let (c, w) = doit 0 (-1) [] in
let n =
if c = (-1) then (-1)
else
match w with
| [] | [_] -> (-1)
| [w; _] -> if c >= w then (-1) else w - c + 1
| _ -> assert false in
Printf.printf "%d\n" n
r6eve