結果
| 問題 | 
                            No.154 市バス
                             | 
                    
| コンテスト | |
| ユーザー | 
                             めうめう🎒
                         | 
                    
| 提出日時 | 2017-02-07 17:58:31 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 994 bytes | 
| コンパイル時間 | 629 ms | 
| コンパイル使用メモリ | 75,100 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-13 08:57:45 | 
| 合計ジャッジ時間 | 1,281 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | WA * 1 | 
| other | AC * 7 WA * 1 | 
ソースコード
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)
#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair
bool check(string str){
	int w = 0, g = 0, r = 0;
	bool flag = true;
	for(int i = 0;i < str.size();i++){
		if(str[i] == 'W'){
			flag = true;
			w++;
		}else if(str[i] == 'G'){
			flag = true;
			if(w < g + 1) return false;
			g++;
		}else{
			flag = false;
			if(w < r + 1 || g < r + 1) return false;
			r++;
		}
	}
	if(flag) return false;
	if(g != r) return false;
	return true;
}
int main() {
	int n;
	string str;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> str;
		bool ans = check(str);
		if(ans) cout << "possible" << endl;
		else cout << "impossible" << endl;
	}
	return 0;
}
            
            
            
        
            
めうめう🎒