結果

問題 No.345 最小チワワ問題
ユーザー nali
提出日時 2019-07-27 10:55:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 513 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 66,560 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-02 10:49:06
合計ジャッジ時間 1,499 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#define INF 1000
using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = INF;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'c') {
      bool f = false;
      for (int j = i + 1; j < s.size(); j++) {
        if (s[j] == 'w' && !f) {
          f = true;
        } else if (s[j] == 'w' && f) {
          ans = min(ans, j - i + 1);
          break;
        }
      }
    }
  }
  cout << (ans != INF ? ans : -1) << endl;
  return 0;
}
0