結果

問題 No.345 最小チワワ問題
ユーザー chiyoda
提出日時 2016-06-21 18:39:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 445 bytes
コンパイル時間 418 ms
コンパイル使用メモリ 57,888 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-25 11:48:29
合計ジャッジ時間 1,332 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int w1 = n;
  int w2 = n;
  int res = n + 1;
  for (int i = n - 1; i >= 0; i--) {
      if (s[i]  == 'w') {
        w2 = w1;
        w1 = i;
      } else if (s[i] == 'c'){
        if (w2 != n ) {
          res = min(res, w2 - i + 1);
        }
      }
  }
  if (res == n + 1) res = -1; 
  cout << res << endl;
  return 0;
}
0