結果
| 問題 | 
                            No.345 最小チワワ問題
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2018-01-01 18:30:42 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 550 bytes | 
| コンパイル時間 | 2,041 ms | 
| コンパイル使用メモリ | 168,920 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-22 23:47:01 | 
| 合計ジャッジ時間 | 3,136 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 28 RE * 1 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main() {
    string s;
    cin >> s;
    vector<int> c, w;
    REP(i, s.length()) {
        if (s[i] == 'c') c.push_back(i);
        if (s[i] == 'w') w.push_back(i);
    }
    int ans = INT_MAX;
    REP(i, c.size()) {
        REP(j, w.size() - 1) {
            if (w[j] > c[i]) {
                ans = min(ans, w[j + 1] - c[i] + 1);
                break;
            }
        }
    }
    cout << ((ans == INT_MAX) ? -1 : ans) << endl;
    return 0;
}