結果
| 問題 | No.154 市バス |
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2022-08-13 02:49:30 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 910 bytes |
| 記録 | |
| コンパイル時間 | 1,183 ms |
| コンパイル使用メモリ | 213,152 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-27 01:12:30 |
| 合計ジャッジ時間 | 2,022 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
cin>>t;
while(t--){
string s;
cin>>s;
int n=s.size();
int G=0,R=0;
rep(i,n){
if(s[i]=='G') G++;
else if(s[i]=='R') R++;
}
if(G!=R || G==0 || n-G-R<G){
cout<<"impossible"<<endl;
continue;
}
int w=-1,g=0,r=0;
bool b=true;
for(int i=n-1;i>=0;i--){
if(s[i]=='G'){
g++;
if(w==-1) w=1;
else w++;
}
else if(s[i]=='R') r++;
else if(w==-1){
b=false;
break;
}
else w=max(w-1,0);
if(g>r){
b=false;
break;
}
}
if(b && w==0) cout<<"possible"<<endl;
else cout<<"impossible"<<endl;
}
return 0;
}
umezo