結果

問題 No.154 市バス
ユーザー cwwcww
提出日時 2016-06-20 02:16:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,021 bytes
コンパイル時間 1,958 ms
コンパイル使用メモリ 164,308 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 09:46:21
合計ジャッジ時間 2,680 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,812 KB
testcase_01 AC 10 ms
6,940 KB
testcase_02 AC 11 ms
6,944 KB
testcase_03 AC 10 ms
6,940 KB
testcase_04 AC 10 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 7 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
using namespace std;
/*関数化ver*/
bool check( string S ){
	int R{}, G{}, W{};
	REP( i, (int)S.size() ){
		//Rが来たら系統を増やす
		if( S[i] == 'R' ){
			R++;
		}
		//Rを持っているGが来たら++,Rを--する
		if( S[i] == 'G' ){
			if( R >= 1 ){
				G++;
				R--;
			}else{
				//Rを持たないGはfalse
				return false;
			}
		}
		//Wの場合は3つの選択肢がある
		if( S[i] == 'W' ){
			//Gを持つ場合,つまり正しい系統の完成
			if( G >= 1 ){
				G--;
				W++;
			//既にWのみ持っている場合
			}else if( W >= 1 ){
				W++;
			//Wしかない場合(R,Gを持たない)はfalse
			}else{
				return false;
			}
		}
	}
	if( R == 0 && G == 0 ){
		return true;
	}
	return false;
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	
	string S;
	while( cin >> S ){
		reverse( S.begin(), S.end() );
		cout << ( check( S ) ? "possible" : "impossible" ) << endl;
	}
	return 0;
}
0