結果

問題 No.154 市バス
ユーザー yumetodoyumetodo
提出日時 2016-06-20 22:08:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,072 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 68,948 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:46:55
合計ジャッジ時間 1,289 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <string>
#include <iostream>
#include <algorithm>
bool check(const std::string& l)
{
	using std::size_t;
	if (l.size() < 3 || 'R' != l.back()) return false;
	size_t r = l.size() - 1;
	size_t g = l.find_last_of('G', l.size() - 2);
	size_t w = l.find_last_of('W', g);
	while (
		std::string::npos != r && 0 != r
		&& std::string::npos != g && 0 != g//Rより前にGがあるか
		&& std::string::npos != w && 0 != w//Gより前にWがあるか
	) {
		r = l.find_last_of('R', r - 1);
		g = l.find_last_of('G', std::min(g - 1, r));
		w = l.find_last_of('W', std::min(w - 1, g));
	}
	return (0 == w || (std::string::npos == r && std::string::npos == l.find_last_of('G', w - 1)));
}
int main()
{
	const auto n = []() { std::string buf; std::getline(std::cin, buf); return static_cast<std::size_t>(std::stoul(buf)); }();
	std::string buf;
	const char* re[] = { "impossible", "possible" };
	for (std::size_t i = 0; i < n && std::getline(std::cin, buf); ++i) {
		const auto r = check(buf.substr(0, buf.find_last_not_of('\n') + 1));
		std::cout << re[r] << std::endl;
	}
}
0