結果
問題 | No.154 市バス |
ユーザー |
![]() |
提出日時 | 2015-02-18 00:17:58 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 251 ms / 2,000 ms |
コード長 | 2,298 bytes |
コンパイル時間 | 759 ms |
コンパイル使用メモリ | 89,096 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 06:36:40 |
合計ジャッジ時間 | 2,420 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
#include <algorithm>#include <cfloat>#include <climits>#include <cmath>#include <complex>#include <cstdio>#include <cstdlib>#include <cstring>#include <functional>#include <iostream>#include <map>#include <memory>#include <queue>#include <set>#include <sstream>#include <stack>#include <string>#include <utility>#include <vector>using namespace std;#define sz size()#define pb push_back#define mp make_pair#define fi first#define se second#define all(c) (c).begin(), (c).end()#define rep(i,a,b) for(int i=(a);i<(b);++i)#define clr(a, b) memset((a), (b) ,sizeof(a))#define MOD 1000000007int main(){int n;cin>>n;rep(i,0,n){string s;cin>>s;{string ss = s;reverse(all(ss));int flag = 0;int flag1 = 0;rep(i,0,ss.sz){if(flag == 0 && (ss[i] == 'W' || ss[i] == 'G')){cout << "impossible" << endl;flag1 = 1;break;}else if(flag == 1 && ss[i] == 'W'){cout << "impossible" << endl;flag1 = 1;break;}else if(flag == 0 && ss[i] == 'R'){flag = 1;}else if(flag == 1 && ss[i] == 'G'){flag = 2;break;}}if(flag1 == 1){continue;}}int c = 0;int flag = 1;int index1 = 0;int index2 = 0;int index3 = 0;for(;;){if(index3==s.sz){flag = 0;break;}if(index1>index2||index2>index3){flag = 0;break;}if(s[index1]=='W'&&s[index2]=='G'&&s[index3]=='R'){c++;if(c==count(all(s),'G')&&c==count(all(s),'R')){break;}index1++;index2++;index3++;}else if(s[index3]!='R'){index3++;}else if(s[index2]!='G'){index2++;}else{index1++;}}if(flag == 0){cout << "impossible" << endl;}else{cout << "possible" << endl;}}return 0;}