結果
| 問題 | 
                            No.345 最小チワワ問題
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-07-27 10:35:28 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 498 bytes | 
| コンパイル時間 | 594 ms | 
| コンパイル使用メモリ | 67,228 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-02 10:48:13 | 
| 合計ジャッジ時間 | 1,545 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 15 WA * 14 | 
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#define INF 1000
using namespace std;
int main() {
  string s;
  cin >> s;
  int c = -1, w = -1, ans = INF;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'c' && c == -1) {
      c = i;
    } else if (s[i] == 'w') {
      if (c != -1 && w == -1) {
        w = i;
      } else if (c!= -1 && w != -1) {
        ans = min(ans, i - c + 1);
        c = w = -1;
      }
    }
  }
  cout << (ans != INF ? ans : -1) << endl;
  return 0;
}