結果

問題 No.154 市バス
ユーザー beetbeet
提出日時 2018-11-12 12:48:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 922 bytes
コンパイル時間 2,034 ms
コンパイル使用メモリ 201,732 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 15:00:52
合計ジャッジ時間 3,439 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed solve(){
  string s;
  cin>>s;
  Int n=s.size();
  Int g=0,r=0,w=0;
  for(Int i=0;i<n;i++){
    if(s[i]=='W') w++;
    if(s[i]=='G') g++,w=0;
    if(s[i]=='R') r++;    
  }
  if((g!=r)||(w>0)){
    cout<<"impossible"<<endl;
    return 0;
  }
  vector<Int> a(g,-1),b(g,-1),c(g,-1);
  for(Int i=n-1,j=g,k=g;i>=0;i--){
    if(s[i]=='R') a[--j]=i;
    if(s[i]=='G') b[--k]=i;
  }
  
  for(Int i=0,j=0;i<n;i++)
    if(s[i]=='W'&&j<g) c[j++]=i;
  
  for(Int i=0;i<g;i++){
    if(a[i]<=b[i]||b[i]<=c[i]){
      cout<<"impossible"<<endl;
      return 0;
    }
  }
  
  cout<<"possible"<<endl;
  return 0;
}

signed main(){
  Int T;
  cin>>T;
  while(T--) solve();
  return 0;
}
0