結果

問題 No.345 最小チワワ問題
ユーザー koturnkoturn
提出日時 2016-02-29 04:28:13
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 902 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 56,476 KB
最終ジャッジ日時 2024-04-27 02:17:55
合計ジャッジ時間 639 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:40: error: ‘numeric_limits’ is not a member of ‘std’
   18 |   std::string::size_type minLen = std::numeric_limits<std::string::size_type>::max();
      |                                        ^~~~~~~~~~~~~~
main.cpp:18:77: error: expected primary-expression before ‘>’ token
   18 |   std::string::size_type minLen = std::numeric_limits<std::string::size_type>::max();
      |                                                                             ^
main.cpp:18:80: error: ‘::max’ has not been declared; did you mean ‘std::max’?
   18 |   std::string::size_type minLen = std::numeric_limits<std::string::size_type>::max();
      |                                                                                ^~~
      |                                                                                std::max
In file included from /usr/include/c++/11/algorithm:62,
                 from main.cpp:2:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: ‘std::max’ declared here
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
main.cpp:33:22: error: ‘numeric_limits’ is not a member of ‘std’
   33 |   if (minLen == std::numeric_limits<std::string::size_type>::max()) {
      |                      ^~~~~~~~~~~~~~
main.cpp:33:59: error: expected primary-expression before ‘>’ token
   33 |   if (minLen == std::numeric_limits<std::string::size_type>::max()) {
      |                                                           ^
main.cpp:33:62: error: ‘::max’ has not been declared; did you mean ‘std::max’?
   33 |   if (minLen == std::numeric_limits<std::string::size_type>::max()) {
      |                                                              ^~~
      |                                                              std::max
In file included from /usr/include/c++/11/algorithm:62,
                 from main.cpp:2:
/usr/include/c++/11/bits/stl_algo.h:3467:5: not

ソースコード

diff #

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


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

  std::string s;
  std::cin >> s;

  std::stack<std::string::size_type> wposStack;
  std::string::size_type minLen = std::numeric_limits<std::string::size_type>::max();
  for (std::string::size_type i = s.length() - 1; i != static_cast<std::string::size_type>(-1); i--) {
    switch (s[i]) {
      case 'c':
        if (wposStack.size() > 1) {
          wposStack.pop();
          minLen = std::min(minLen, wposStack.top() - i + 1);
          wposStack.pop();
        }
        break;
      case 'w':
        wposStack.push(i);
        break;
    }
  }
  if (minLen == std::numeric_limits<std::string::size_type>::max()) {
    std::cout << -1 << std::endl;
  } else {
    std::cout << minLen << std::endl;
  }

  return EXIT_SUCCESS;
}
0