結果

問題 No.154 市バス
ユーザー cwwcww
提出日時 2016-06-10 20:31:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,411 bytes
コンパイル時間 1,414 ms
コンパイル使用メモリ 163,820 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:29:47
合計ジャッジ時間 2,011 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
5,248 KB
testcase_01 AC 10 ms
5,248 KB
testcase_02 AC 10 ms
5,376 KB
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 10 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	string S;
	REP( i, N )
	{
		cin >> S;
		//reverse(S.begin(), S.end());
		//1つも無い場合
		if( S.find_first_of( 'R' ) == string::npos ||
			S.find_first_of( 'G' ) == string::npos ||
			S.find_first_of( 'W' ) == string::npos )
		{
			cout << "impossible" << endl;
			continue;
		}
		//最後のG以降にWが有る場合
		auto pos = S.find_last_of( 'G' );
		if( S.find( 'W', pos ) != string::npos )
		{
			cout << "impossible" << endl;
			continue;
		}
		//最後のR以降にGが有る場合
		pos = S.find_last_of( 'R' );
		if( S.find( 'G', pos ) != string::npos)
		{
			cout << "impossible" << endl;
			continue;
		}
		//最初のG以前にRが有る場合
		bool flag = true;
		REP( i, (int)S.find( 'G' ) )
		{
			if( S[i] == 'R' )
			{
				cout << "impossible" << endl;
				flag = false;
				break;
			}
		}
		if( !flag ){ continue; }
		//GとRの数が等しく無い場合
		int countG{},countR{};
		REP( i, (int)S.size() )
		{
			if( S[i] == 'G' )
			{
				countG++;
			}
			if( S[i] == 'R')
			{
				countR++;
			}
		}
		cout << ( (countG > 0 && countR > 0 && countG == countR ) ? "possible" : "impossible" ) << endl;
	}
	return 0;
}
0