結果

問題 No.345 最小チワワ問題
ユーザー aaaaaaiu
提出日時 2019-07-27 14:33:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 492 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 194,036 KB
最終ジャッジ日時 2025-01-07 09:37:40
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 7 WA * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
      |         ^~~~~

ソースコード

diff #

#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);
        }
    }
    cout << ans << endl;
    return 0;
}
0