結果

問題 No.154 市バス
ユーザー やまぞうやまぞう
提出日時 2015-04-03 00:45:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 486 ms
コンパイル使用メモリ 69,800 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 08:27:59
合計ジャッジ時間 1,176 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <fstream>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

void possible()
{
	cout << "possible" << endl;
}

void impossible()
{
	cout << "impossible" << endl;
}

bool resolve(const string& s)
{
	int indexR = -1;
	int indexG = -1;
	int indexW = -1;
	int countR = 0;
	int countG = 0;
	int countW = 0;
	for (string::size_type i = 0; i < s.length(); i++) {
		char ch = s[i];
		switch (ch) {
		case 'R':
			countR++;
			indexR = i;
			break;
		case 'G':
			countG++;
			indexG = i;
			break;
		case 'W':
			countW++;
			indexW = i;
			break;
		}
		if (countR > countG || countG > countW) {
			impossible();
			return false;
		}
	}
	if (countR == 0 || countR != countG) {
		impossible();
		return false;
	}
	if (indexW > indexG) {
		impossible();
		return false;
	}
	possible();
	return true;
}

int main(int argc, char **argv)
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		resolve(s);
	}
	return 0;
}

0