結果

問題 No.154 市バス
ユーザー 古寺いろは古寺いろは
提出日時 2015-03-27 01:21:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 745 bytes
コンパイル時間 1,398 ms
コンパイル使用メモリ 160,340 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 08:25:17
合計ジャッジ時間 2,093 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

bool check(string S){
	vector<int> count(3);
	bool flag = true;
	int pp = 0;
	for (int i = S.size() - 1; i >= 0; i--)
	{
		int r = 0;
		if (S[i] == 'G') r = 1;
		if (S[i] == 'R') r = 2;
		count[r]++;
		if (count[0] != 0 && count[1] == 0) return false;
		if (count[0] != 0 && count[2] == 0) return false;
		if (count[2] < count[1]) return false;
		if (r == 0) pp = min(pp + 1, count[1]);
	}
	if (count[2] != count[1]) return false;
	if (count[0] < count[1]) return false;
	if (pp != count[1]) return false;
	return true;
}

int main() {
	int N;
	cin >> N;
	for (int t = 0; t < N; t++)
	{
		string S;
		cin >> S;
		if (check(S)) cout << "possible" << endl;
		else cout << "impossible" << endl;
	}
}

0