結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 24 ms
6,940 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 indexW = string::npos;
	string::size_type indexG = string::npos;
	string::size_type indexR = string::npos;
	int countW = 0;
	int countG = 0;
	int countR = 0;
	for (string::size_type i = 0; i < s.length(); i++) {
		char ch = s[i];
		switch (ch) {
		case 'W':
			countW++;
			index_list[i] = indexW;
			indexW = i;
			break;
		case 'G':
			countG++;
			index_list[i] = indexG;
			indexG = i;
			break;
		case 'R':
			countR++;
			index_list[i] = indexR;
			indexR = i;
			break;
		}
	}
	if (countW < countG || countG != countR) {
		impossible();
		return;
	}
	for (int i = 0; i < countR; i++) {
		if (indexW > indexG || indexG > indexR) {
			impossible();
			return;
		}
		indexW = index_list[indexW];
		indexG = index_list[indexG];
		indexR = index_list[indexR];
	}
	possible();
}

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