結果

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    string s;
    cin>>s;
    int n=s.size();

    int res=n+n;
    for(int i=0; i<n; ++i) {
        if (s[i]=='c') {
            int cnt=0;
            for(int j=i+1; j<n; ++j) {
                if (s[j]=='w') cnt++;
                if (cnt==2) res=min(res, j-i+1);
            }
        }
    }
    cout<<(res <= n ? res : -1)<<endl;
}
0