結果

問題 No.154 市バス
ユーザー edamame882edamame882
提出日時 2019-08-03 22:40:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,435 bytes
コンパイル時間 1,630 ms
コンパイル使用メモリ 164,756 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 16:43:05
合計ジャッジ時間 2,539 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

bool solve(string& x){
  int rcnt = 0;
  int gcnt = 0;

  bool firstG = false;

  rep(i,x.size()){
    if(x[i] == 'R') rcnt++;
    if(x[i] == 'G'){
      rcnt--;
      if(rcnt < 0) return false;
      firstG = true;
      gcnt++;
    }
    if(x[i] == 'W'){
      if(firstG == false) return false;
      if(gcnt > 0) gcnt--;
    }
  }
  if(gcnt == 0 && rcnt == 0) return true;
  else return false;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  rep(i,n){
    string x;
    cin >> x;
    reverse(all(x));
    cout << (solve(x)?"possible":"impossible") << endl;
  }
  return 0;
}
0