結果
問題 | No.345 最小チワワ問題 |
ユーザー |
![]() |
提出日時 | 2022-05-21 18:49:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 676 bytes |
コンパイル時間 | 635 ms |
コンパイル使用メモリ | 70,716 KB |
最終ジャッジ日時 | 2025-01-29 13:08:42 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include <iostream> #include <vector> #include <string> using namespace std; int main() { string S; cin >> S; int ans = -1; int i = 0; int len = 200; char stat = 'c'; int tmp; while( true ) { if( S[i] == '\0' ) { if( stat == 'c' ) { break; } i = tmp+1; stat = 'c'; continue; } switch( stat ) { case 'c': if( S[i] == 'c' ) { stat = 'w'; tmp = i; } i++; break; case 'w': if( S[i] == 'w' ) { stat = 'W'; } i++; break; case 'W': if( S[i] == 'w' ) { len = min( len, i - tmp + 1 ); i = tmp; stat = 'c'; } i++; } } len = len==200 ? -1: len; cout << len << endl; return 0; }