結果

問題 No.154 市バス
ユーザー ferinferin
提出日時 2017-03-03 01:42:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,280 bytes
コンパイル時間 1,310 ms
コンパイル使用メモリ 164,168 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 10:11:10
合計ジャッジ時間 2,022 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL<<25)     //33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
  int t;
  string s[1010];
  cin >> t;
  REP(i, t) cin >> s[i];

  REP(i, t) {
    stack<char> a;
    while(a.size()) a.pop();
    bool w = false, g = false, r = false;
    int ww = INF, gg = INF, www = INF, ggg = INF;
    REP(j, s[i].size()) {
      if(s[i][j] == 'G') {
        a.push('G');
        g = true;
        gg = j;
        ggg = min(ggg, (int)j);
      }
      else if(s[i][j] == 'R') {
        r = true;
        if(a.size() && a.top() == 'G') {
          a.pop();
        } else {
          a.push('a');
          break;
        }
      } else if(s[i][j] == 'W') {
        w = true;
        ww = j;
        www = min(www, (int)j);
      }
    }
    if(a.empty() && g && w && r && ww < gg && www < ggg) {
      cout << "possible" << endl;
    } else {
      cout << "impossible" << endl;
    }
  }

  return 0;
}
0