結果

問題 No.154 市バス
コンテスト
ユーザー SutoraRen
提出日時 2016-06-30 16:45:27
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 666 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 932 ms
コンパイル使用メモリ 176,784 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-30 17:38:00
合計ジャッジ時間 1,887 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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