結果

問題 No.345 最小チワワ問題
ユーザー KuraKura
提出日時 2019-02-26 22:26:09
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 1,199 ms
コンパイル使用メモリ 160,196 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-01 05:12:58
合計ジャッジ時間 1,935 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
int main() {
	string s; cin >> s; int ans = s.length() + 1; int a = s.length();
	for (int i = 0; i <  a- 2; i++) {
		if (s[i] == 'c') {
			for (int j = i+1; j < a-1; j++) {
				if (s[j] == 'w') {
					for (int k = j + 1; k < s.length(); k++) {
						if (s[k] == 'w') {
							ans = min(ans, k-i+1);
							break;
						}
					}
					break;
				}
			}
		}
	}
	if (ans == s.length() + 1) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
}
0