結果

問題 No.345 最小チワワ問題
ユーザー hiro71687k
提出日時 2023-04-16 17:29:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 761 bytes
コンパイル時間 3,830 ms
コンパイル使用メモリ 250,968 KB
最終ジャッジ日時 2025-02-12 09:13:53
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=1444999999;
ll mod=1000000007;
int main(){
    string s;
    cin >> s;
    ll ans=inf;
    for (ll i = 0; i < s.size(); i++)
    {
        if (s[i]!='c')
        {
            continue;
        }
        ll w=0;
        for (ll j = i+1; j < s.size(); j++)
        {
            if (s[j]=='w')
            {
                w+=1;
                if (w==2)
                {
                    ans=min(ans,j-i+1);
                    break;
                }
            }
        }
    }
    if (ans==inf)
    {
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    
}
0