結果
問題 | No.154 市バス |
ユーザー |
![]() |
提出日時 | 2018-11-12 12:48:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 922 bytes |
コンパイル時間 | 1,754 ms |
コンパイル使用メモリ | 196,560 KB |
最終ジャッジ日時 | 2025-01-06 16:29:23 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | AC * 8 |
ソースコード
#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 HEREsigned 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;}