結果
| 問題 | 
                            No.345 最小チワワ問題
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-03-01 01:27:32 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 320 bytes | 
| コンパイル時間 | 445 ms | 
| コンパイル使用メモリ | 56,212 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-25 11:35:29 | 
| 合計ジャッジ時間 | 1,333 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 29 | 
ソースコード
#include <iostream>
#include <cstring>
using namespace std;
int main() {
	string s;
	cin>>s;
	int ans=100;
	int S=s.size(),w1=S,w2=S;
	for(int i=S-1;i>=0;i--){
		if(s[i]=='w'){
			w1=w2;
			w2=i;
		}
		if(s[i]=='c'&&w1!=S){
			ans=min(ans,w1-i+1);
		}
	}
	if(ans==100)cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}