結果

問題 No.345 最小チワワ問題
ユーザー fura
提出日時 2020-03-15 19:12:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 466 bytes
コンパイル時間 2,562 ms
コンパイル使用メモリ 191,500 KB
最終ジャッジ日時 2025-01-09 07:05:20
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

int main(){
	string s; cin>>s;
	int n=s.length();

	int ans=INF;
	rep(i,n) for(int j=i+1;j<=n;j++) {
		int stage=0;
		for(int x=i;x<j;x++){
			if     (stage==0 && s[x]=='c') stage++;
			else if(stage==1 && s[x]=='w') stage++;
			else if(stage==2 && s[x]=='w') stage++;
		}
		if(stage==3) ans=min(ans,j-i);
	}
	printf("%d\n",ans<INF?ans:-1);

	return 0;
}
0