結果

問題 No.154 市バス
ユーザー temptemp
提出日時 2015-02-17 23:48:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,283 bytes
コンパイル時間 1,426 ms
コンパイル使用メモリ 83,448 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-03 08:59:10
合計ジャッジ時間 2,606 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
4,380 KB
testcase_01 AC 25 ms
4,380 KB
testcase_02 AC 25 ms
4,508 KB
testcase_03 AC 25 ms
4,384 KB
testcase_04 AC 26 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 21 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

bool is_possible(string s) {
  int r, g, w;
  bool ok = false;
  r = g = w = 0;
  // std::cout << s << std::endl;
  for (int i = s.size()-1; i >= 0; i--) {
    if (s[i] == 'G') {
      if (r <= g) return false;
      g++;
      // std::cout << "g" << std::endl;
    }else if (s[i] == 'W'){
      if (!ok) {
        if (g <= 0 || r <= 0) return false;
        g--; r--;
        ok = true;
      }else {
        if (g > 0 && r > 0) {
          g--; r--;
        }
      }
      // std::cout << "w" << std::endl;
    }else {
      r++;
      // std::cout << "r" << std::endl;
    }
  }
  if (r > 0 || g > 0) return false;
  return true;
}

int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    string s;
    cin >> s;
    if (is_possible(s)) {
      std::cout << "possible" << std::endl;
    }else {
      std::cout << "impossible" << std::endl;
    }
  }
}
0