結果

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

テストケース

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

ソースコード

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

		ans[i] = isPossible;
	}

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