結果

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

ソースコード

diff #

#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <string>


int
main()
{
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  std::string s;
  std::cin >> s;
  int len = static_cast<int>(s.length());
  int minLen = 101;
  // !!!!
  for (int i = 0; i < len; i++) {
    if (s[i] != 'c') continue;
    for (int j = i + 1; j < len; j++) {
      if (s[j] != 'w') continue;
      for (int k = j + 1; k < len; k++) {
        if (s[k] == 'w') {
          minLen = std::min(minLen, k - i + 1);
        }
      }
    }
  }
  std::cout << (minLen == 101 ? -1 : minLen) << std::endl;

  return EXIT_SUCCESS;
}
0