結果
| 問題 | 
                            No.345 最小チワワ問題
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-02-29 04:10:25 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 713 bytes | 
| コンパイル時間 | 715 ms | 
| コンパイル使用メモリ | 65,164 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-24 12:40:32 | 
| 合計ジャッジ時間 | 1,502 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 WA * 6 | 
ソースコード
#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<int> wposStack;
  int maxLen = -1;
  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();
          maxLen = std::max(maxLen, static_cast<int>(wposStack.top() - i + 1));
          wposStack.pop();
        }
        break;
      case 'w':
        wposStack.push(i);
        break;
    }
  }
  std::cout << maxLen << std::endl;
  return EXIT_SUCCESS;
}