結果

問題 No.154 市バス
ユーザー amtgjwamtgjw
提出日時 2018-06-06 11:24:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 483 ms
コンパイル使用メモリ 65,216 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 22:42:05
合計ジャッジ時間 1,310 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
4,380 KB
testcase_01 AC 28 ms
4,376 KB
testcase_02 AC 28 ms
4,376 KB
testcase_03 AC 28 ms
4,376 KB
testcase_04 AC 29 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 23 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)
#define PER(i,n)	for(int i=0;i>(n);--i)
#define PERS(i,s,t)	for(int i=(s);i>(t);--i)

#define INF 		2000000007
#define MINF		-200000007
#define MOD			17 	
// 2^20

#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

//int dp[4912];

int main(){
	int N;cin>>N;

	REP(i,N){
		string str;cin>>str;
		bool flag = true;
		int cntw=0,cntr=0,cntg=0;
		PERS(j,str.size()-1,-1){
			if(str[j]=='R'){cntr++;}
			else if(str[j]=='G'){cntg++;}
			else cntw++;
			if(cntr<cntg) {flag = false;break;}
			if((cntw&&!cntr) || (cntw&&!cntg)){flag=false;break;}
		}
		if(cntw < cntr || cntr!=cntg || !cntg) flag = false;
		cntw=cntg=0;
		REP(j,str.size()){
			if(str[j]=='W')cntw++;
			else if(str[j]=='G')cntg++;
			if(cntg>cntw){flag=false;break;}
		}
		
		cout << (flag ? "possible\n" : "impossible\n") ;
	}


	return 0;
}
0