結果

問題 No.154 市バス
ユーザー ttakanottakano
提出日時 2017-11-28 11:29:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 1,367 ms
コンパイル使用メモリ 159,208 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 10:28:57
合計ジャッジ時間 2,332 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define GET_ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007;

int main(){
  int n;
  cin>>n;
  REP(i,n){
    string s;
    cin>>s;
    int w=0;
    int g=0;
    int r=0;
    bool flag=1;
    int set=0;
    for(int j=s.size()-1;j>=0;j--){
      if(s[j]=='G'){g++;}
      else if(s[j]=='R'){r++;}
      else if(s[j]=='W'){
        w++;
        set=min(set+1,g);
      }
      if(w!=0&&g==0)flag=0;
      if(w!=0&&r==0)flag=0;
      if(r<g)flag=0;
    }
    if(r!=g||w<g||set!=g)flag=0;
    string ans=flag?"possible":"impossible";
    print(ans);
  }
}
0