結果

問題 No.154 市バス
ユーザー hotpepsihotpepsi
提出日時 2015-02-18 00:00:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 914 bytes
コンパイル時間 501 ms
コンパイル使用メモリ 63,528 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 07:46:21
合計ジャッジ時間 1,614 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstring>

using namespace std;

bool can(const string &s) {
	string r = s;
	reverse(r.begin(), r.end());
	while (r.length() > 1) {
		int pos = r.find('R', 1);
		if (pos < 0) {
			break;
		}
		r = r.substr(0, pos) + r.substr(pos + 1);
		pos = r.find('G', pos);
		if (pos < 0) {
			return false;
		}
		r = r.substr(0, pos) + r.substr(pos + 1);
		pos = r.find('W', pos);
		if (pos < 0) {
			return false;
		}
		r = r.substr(0, pos) + r.substr(pos + 1);
	}
	if (r.length() < 3 || r[0] != 'R' || r[1] != 'G') {
		return false;
	}
	for (int i = 2; i < (int)r.length(); ++i) {
		if (r[i] != 'W') {
			return false;
		}
	}
	return true;
}

int main(int argc, char *argv[]) {
	string s;
	getline(cin, s);
	int T = atoi(s.c_str());
	for (int i = 0; i < T; ++i) {
		getline(cin, s);
		cout << (can(s) ? "possible" : "impossible") << endl;
	}
	return 0;
}
0