結果

問題 No.345 最小チワワ問題
ユーザー capythm
提出日時 2016-03-03 00:13:57
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 449 bytes
コンパイル時間 492 ms
コンパイル使用メモリ 57,308 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-25 11:35:49
合計ジャッジ時間 1,398 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  string s;
  cin >> s;
  int ret = 101;
  for( int i=0; i<s.size(); i++ ){
    if( s[i] == 'c' ){
      int c = 0;
      for( int j=i+1; j<s.size(); j++ ){
        if( s[j] == 'w' ) c++;
        if( c == 2 ){
          ret = min( ret, j-i+1 );
          break;
        }
      }
    }
  }
  if( ret > 100 ) cout << -1 << endl;
  else cout << ret << endl;
}
0