結果

問題 No.154 市バス
ユーザー SutoraRenSutoraRen
提出日時 2016-06-30 16:45:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 666 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 158,664 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 09:49:26
合計ジャッジ時間 2,549 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
6,812 KB
testcase_01 AC 31 ms
6,944 KB
testcase_02 AC 31 ms
6,944 KB
testcase_03 AC 31 ms
6,944 KB
testcase_04 AC 30 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 25 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

int N;
string S;

int main(){
	cin>>N;
	REP(i,N){
		cin>>S;
		int w=0;
		bool f=false,p=false;
		REP(j,S.length()){
			if (S[j]=='W'){
				w++;
				f=true;
			}else if (S[j]=='G'){
				w--;
				f=false;
				if (w<0){
					p=true;
				}
			}
		}
		if (p || f){
			cout<<"impossible"<<endl;
			continue;
		}
		int g=0;
		REP(j,S.length()){
			if (S[j]=='G'){
				g++;
			}else if (S[j]=='R'){
				g--;
				if (g<0){
					p=true;
				}
			}
		}
		if (g || p){
			cout<<"impossible"<<endl;
			continue;
		}
		cout<<"possible"<<endl;
	}
	return 0;
}
0