結果

問題 No.154 市バス
ユーザー やまぞうやまぞう
提出日時 2015-03-31 00:53:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,400 bytes
コンパイル時間 710 ms
コンパイル使用メモリ 68,456 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 08:27:40
合計ジャッジ時間 1,402 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}

void resolve(const string& s)
{
	vector<string::size_type> index_list(s.length());
	string::size_type indexR = string::npos;
	string::size_type indexG = string::npos;
	string::size_type indexW = string::npos;
	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++;
			index_list[i] = indexR;
			indexR = i;
			break;
		case 'G':
			countG++;
			index_list[i] = indexG;
			indexG = i;
			break;
		case 'W':
			countW++;
			index_list[i] = indexW;
			indexW = i;
			break;
		}
	}
	if (countR != countG || countG > countW) {
		impossible();
		return;
	}
	for (int i = 0; i < countR; i++) {
		if (countG > countW) {
			impossible();
			return;
		}
		if (indexR < indexG || indexG < indexW) {
			impossible();
			return;
		}
		indexR = index_list[indexR];
		countR--;
		indexG = index_list[indexG];
		countG--;
		do {
			indexW = index_list[indexW];
			countW--;
		} while (indexW > indexG);
	}
	possible();
}

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