結果

問題 No.154 市バス
ユーザー kk
提出日時 2020-09-25 06:18:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 807 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 199,196 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 14:23:29
合計ジャッジ時間 2,755 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

bool check(const string &s) {
  int g = count(s.begin(), s.end(), 'G');
  int r = count(s.begin(), s.end(), 'R');
  int w = count(s.begin(), s.end(), 'W');

  if (!g || !r || !w) return false;
  if (g != r) return false;
  if (w < g) return false;

  if (s.find_last_of("W") > s.find_last_of("G")) return false;
  int stk = 0;
  for (char c: s) {
    if (c == 'G') ++stk;
    else if (c == 'R') {
      if (--stk < 0)
        return false;
    }
  }
  return !stk;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    if (check(s))
      cout << "possible" << endl;
    else
      cout << "impossible" << endl;
  }
  
  return 0;
}
0