結果
| 問題 | 
                            No.154 市バス
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-08-30 12:21:11 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 967 bytes | 
| コンパイル時間 | 524 ms | 
| コンパイル使用メモリ | 65,920 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-13 08:42:40 | 
| 合計ジャッジ時間 | 1,225 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 7 WA * 1 | 
ソースコード
#include <string>
#include <iostream>
#include <cstdint>
typedef int_fast16_t int16;
int main() {
	int16 n;
	std::cin>>n;
	std::string a;
	std::getline(std::cin,a);
	for(int i=0;i<n;i++){
		bool is_error=false;
		std::string case_;
		std::getline(std::cin,case_);
		int red_num=0;
		int green_num=0;
                for(auto color:case_){
			switch(color){
			case 'R':
				red_num++;
				break;
			case 'G':
				green_num++;
				break;
			}
			if(red_num>green_num){
				is_error=true;
			}
		}
		auto last=case_.rbegin();
		auto last2=last;
		++last2;
		auto it=last;
		int red_num_copy=red_num;
		while(it!=case_.rend()){
			if(red_num_copy==0){
				if(*it!='G'){
					is_error=true;
				}
				break;
			}
			if(*it=='G'){
				break;
			}
			if(*it=='R'){
				red_num_copy--;
			}
			++it;
		}
		if(*last=='W'||*last2=='W'||red_num!=green_num||is_error||case_.size()<3){
			std::cout<<"impossible"<<std::endl;
		}else{
			std::cout<<"possible"<<std::endl;
		}
	}
}