結果

問題 No.154 市バス
ユーザー hotpepsihotpepsi
提出日時 2015-02-18 01:22:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,110 bytes
コンパイル時間 1,003 ms
コンパイル使用メモリ 63,440 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-21 07:59:22
合計ジャッジ時間 2,581 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
5,248 KB
testcase_01 AC 138 ms
5,376 KB
testcase_02 AC 140 ms
5,376 KB
testcase_03 AC 140 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 264 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());
	int wcnt = 1;
	while (r.length() > 1) {
		int pos = r.find('R', 1);
		if (pos < 0) {
			break;
		}
		++wcnt;
		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);
		for (int i = pos; i < (int)r.length(); ++i) {
			if (r[i] == 'W') {
				r[i] = 'X';
			}
		}
	}
	if (r.length() < 3 || r[0] != 'R') {
		return false;
	}
	int gpos = 1;
	while (gpos < (int)r.length() && r[gpos] == 'X') {
		++gpos;
		--wcnt;
	}
	if (gpos + 2 > (int)r.length() || r[gpos] != 'G') {
		return false;
	}
	for (int i = gpos + 1; i < (int)r.length(); ++i) {
		if (r[i] != 'W' && r[i] != 'X') {
			return false;
		}
		--wcnt;
	}
	return wcnt <= 0;
}

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