結果

問題 No.345 最小チワワ問題
ユーザー masamasa
提出日時 2016-02-26 22:25:19
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 476 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 56,040 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-25 11:22:54
合計ジャッジ時間 1,311 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;

const int inf = 1e9;

int main() {
	string s;
	cin >> s;
	int ans = inf;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'c') {
			int len = inf;
			int w = 0;
			for (int j = i + 1; j < s.size(); j++) {
				if (s[j] == 'w') {
					w++;
					if (w == 2) {
						len = j - i + 1;
						break;;
					}
				}
			}
			ans = min(ans, len);
		}
	}
	if (ans == inf) {
		ans = -1;
	}
	cout << ans << endl;
	return 0;
}
0