結果

問題 No.345 最小チワワ問題
ユーザー square1001
提出日時 2016-10-29 18:09:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 2,036 ms
コンパイル使用メモリ 168,164 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-25 11:54:29
合計ジャッジ時間 2,432 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
	cin >> s;
	int ret = s.size() + 1;
	for(int i = 0; i < s.size(); i++) {
		for(int j = i + 1; j <= s.size(); j++) {
			string t = s.substr(i, j - i);
			int pos = 0;
			for(; pos < j - i && t[pos] != 'c'; pos++);
			for(pos++; pos < j - i && t[pos] != 'w'; pos++);
			for(pos++; pos < j - i && t[pos] != 'w'; pos++);
			if(pos < j - i) ret = min(ret, j - i);
		}
	}
	if(ret != s.size() + 1) cout << ret << endl;
	else cout << -1 << endl;
	return 0;
}
0