結果

問題 No.154 市バス
ユーザー 👑 horiesinitihoriesiniti
提出日時 2016-07-20 15:20:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 941 bytes
コンパイル時間 517 ms
コンパイル使用メモリ 60,212 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 11:56:50
合計ジャッジ時間 1,441 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
void f(){
	//始発バスがいきなり終バスでもあるということも考慮すると?
	int g=0,r=0,w=0;
	std::string str;
	std::cin>>str;
	
	for(int i=0;i<str.size();i++){
		char c=str[i];
		if(c=='W'){
			w++;
		}else if(c=='G'){
			g++;
		}else if(c=='R'){
			r++;
		}
		if((r>w)||(g>w)){
			printf("impossible\n");
			return;
		}
	}
	g=0;
	w=0;
	r=0;
	std::reverse(str.begin(),str.end());
	for(int i=0;i<str.size();i++){
		char c=str[i];
		if(c=='G'){
			g++;
		}else if(c=='R'){
			r++;
		}else if(c=='W'){
			w++;
		}
		if(((r==0)||(g==0))&&(c=='W')){
			printf("impossible\n");
			return;
		}
		if(g>r){
			printf("impossible\n");
			return ;
		}
	}

	if((w>=g)&&(g==r)){
		printf("possible\n");
	}else{
		printf("impossible\n");
	}
}

int main() {
	// your code goes here
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		f();
	}
	
	return 0;
}
0