結果

問題 No.345 最小チワワ問題
コンテスト
ユーザー kya_ski
提出日時 2020-04-18 21:35:12
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 509µs
コード長 743 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 910 ms
コンパイル使用メモリ 180,980 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-09 22:06:46
合計ジャッジ時間 2,812 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

bool is_cww (const string &s) {
    bool c = false, w = false, ww = false;
    for (const char &ch : s) {
        if (!c and !w and !ww) {
            if (ch == 'c') c = true;
        } else if (c and !w and !ww) {
            if (ch == 'w') w = true;
        } else if (c and w and !ww) {
            if (ch == 'w') ww = true;
        }
    }
    return (c and w and ww);
}

int main() {
    string s;
    cin >> s;
    
    int ans = 111;
    for (int i = 0; i < s.length(); i++) {
        for (int len = 1; i + len <= s.length(); len++) {
            if (is_cww(s.substr(i, len))) ans = min(ans, len);
        }
    }
    
    if (ans == 111) ans = -1;
    cout << ans << '\n';
    return 0;
}
0