結果

問題 No.154 市バス
ユーザー nksk38nksk38
提出日時 2017-07-27 11:54:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,260 bytes
コンパイル時間 759 ms
コンパイル使用メモリ 81,204 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 10:17:42
合計ジャッジ時間 1,409 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, string> pls;

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

	for (int i = 0; i < N; i++) 
	{
		string s,ans="possible"; cin >> s;

		int white = 0,red = 0, green = 0;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == 'G')green++;
			if (s[i] == 'R')red++;
			if (s[i] == 'W')white++;
		}

		if (s[s.size() - 1] != 'R' || s[0] != 'W' || green != red || white < green) {
			cout << "impossible" << endl;
		}
		else 
		{
			white = 0,red = 0, green = 0;
			for (int i = s.size()-1; i >= 0; i--) {
				if (s[i] == 'R') {
					red++;
					if (green >= red || white >= red) {
						ans = "impossible";
						break;
					}
				}
				if (s[i] == 'G') {
					green++;
					if (green > red || green <= white) {
						ans = "impossible";
						break;
					}
				}
				if (s[i] == 'W') {
					green--;
					red--;
				}
			}
			cout << ans << endl;
		}
	}
	return 0;
}
0