結果
問題 | No.345 最小チワワ問題 |
ユーザー |
![]() |
提出日時 | 2020-07-25 00:54:44 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,018 bytes |
コンパイル時間 | 16,307 ms |
コンパイル使用メモリ | 401,676 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-26 00:46:40 |
合計ジャッジ時間 | 12,795 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
use std::io::Read;fn read<T: std::str::FromStr>() -> T {let token: String = std::io::stdin().bytes().map(|c| c.ok().unwrap() as char).skip_while(|c| c.is_whitespace()).take_while(|c| !c.is_whitespace()).collect();token.parse().ok().unwrap()}fn cww(s: &[char]) -> bool {let mut c = 0;let mut w = 0;for &x in s {if x == 'c' {c += 1;}if x == 'w' && c >= 1 {w += 1;}if c >= 1 && w >= 2 {return true;}}return false;}fn main() {let s: String = read();let s = s.chars().collect::<Vec<_>>();let mut ans = std::usize::MAX;for i in 0..s.len() {for j in i..s.len() {if cww(&s[i..=j]) {ans = std::cmp::min(ans, j - i + 1);}}}println!("{}",if ans == std::usize::MAX {-1} else {ans as i32});}