結果

問題 No.154 市バス
ユーザー masamasa
提出日時 2015-02-18 00:11:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 847 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 62,272 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 07:50:46
合計ジャッジ時間 1,207 ms
ジャッジサーバーID
(参考情報)
judge3 / 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 WA -
testcase_07 AC 22 ms
5,376 KB
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int t, w, g, r;
	string s;

	cin >> t;
	vector<bool> ans(t, false);
	for (int i = 0; i < t; i++) {
		cin >> s;
		int n = s.size();
		bool isPossible;

		w = g = r = 0;
		for (int i = n - 1; i >= 0; i--) {
			isPossible = true;
			if (s[i] == 'W') {
				w++;
			} else if (s[i] == 'G') {
				g++;
				if (g <= w || g > r) {
					isPossible = false;
					break;
				}
			} else if (s[i] == 'R') {
				r++;
				if (r <= g || r <= w) {
					isPossible = false;
					break;
				}
			}
		}
		if (!isPossible) {
			if (w == 0 || r != g) {
				isPossible = false;
			}
		}

		ans[i] = isPossible;
	}

	for (int i = 0; i < t; i++) {
		cout << (ans[i] ? "possible" : "impossible") << endl;
	}
	return 0;
}
0