結果

問題 No.154 市バス
ユーザー koyumeishikoyumeishi
提出日時 2015-02-18 00:10:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,095 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 79,880 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 09:08:44
合計ジャッジ時間 1,338 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;


void solve(){
	char c[2000];
	scanf("%s", c);
	string s = c;

	deque<int> w;
	deque<int> g;
	deque<int> r;

	int n = s.size();
	for(int i=0; i<n; i++){
		if(s[i] == 'W'){
			w.push_back(i);
		}else if(s[i] == 'G'){
			if(w.size() > 0){
				w.pop_front();
				g.push_back(i);
			}else{
				cout << "impossible" << endl;
				return;
			}
		}else if(s[i] == 'R'){
			if(g.size() > 0){
				g.pop_front();
				r.push_back(i);
			}else{
				cout << "impossible" << endl;
				return;
			}
		}
	}

	if(g.size()>0 || r.size()==0){
		cout << "impossible" << endl;
		return;
	}
	if(w.size()>0 && r.size()>0 && w.back() > r.back()){
		cout << "impossible" << endl;
		return;
	}

	for(int i=r.back(); i>=0; i--){
		if(s[i] == 'G') break;
		else if(s[i] == 'W'){
			cout << "impossible" << endl;
			return;
		}
	}

	cout << "possible" << endl;

}

int main(){
	int T;
	cin >> T;
	while(T--){
		solve();
	}

}
0