結果
| 問題 | No.345 最小チワワ問題 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-07-27 14:34:40 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 522 bytes |
| 記録 | |
| コンパイル時間 | 1,744 ms |
| コンパイル使用メモリ | 193,464 KB |
| 最終ジャッジ日時 | 2025-01-07 09:37:50 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 WA * 14 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:29: warning: ‘start’ may be used uninitialized [-Wmaybe-uninitialized]
18 | ans = min(ans, i-start+1);
| ~^~~~~~
main.cpp:9:9: note: ‘start’ was declared here
9 | int start;
| ^~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
string s;
cin>>s;
int cnt = 0;
int start;
int ans = 1e9;
for (int i = 0; i < s.size(); i++) {
if (cnt == 0 && s[i] == 'c') {
cnt++;
start = i;
} else if (cnt == 1 && s[i] == 'w') cnt++;
else if (cnt == 2 && s[i] == 'w') {
cnt = 0;
ans = min(ans, i-start+1);
}
}
if (ans == 1e9) ans = -1;
cout << ans << endl;
return 0;
}