結果

問題 No.345 最小チワワ問題
ユーザー gasin
提出日時 2016-02-29 22:33:40
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 484 bytes
コンパイル時間 1,227 ms
コンパイル使用メモリ 158,084 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-25 11:35:27
合計ジャッジ時間 2,103 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
using namespace std;

string str;
int ans = INF;

int main(){	
	cin >> str;
	int s = str.size();
	rep(i,s){
		if(str[i] != 'c') continue;
		int st = i;
		for(int j = i+1; j < s; j++){
			if(str[j] != 'w') continue;
			for(int k = j+1; k < s; k++){
				if(str[k] == 'w'){
					ans = min(k-st+1,ans);
					break;
				}
			}
		}
	}
	if(ans == INF) cout << -1 << endl;
	else cout << ans << endl;
}
0