結果

問題 No.154 市バス
ユーザー takana-sky07takana-sky07
提出日時 2019-07-29 20:23:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 836 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 69,620 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 12:00:50
合計ジャッジ時間 1,438 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/*
* 154_sample.cpp
* 
* No.154 soX
* Փx2.5
*/

#include <iostream>

// ֐
bool judge(const char* s) {
	// ꂼ̐F̃JEg
	int w = 0;
	int g = 0;
	int r = 0;
	// RȊO̍Ō̕ۑp
	char rr = '\0';
	for (int i=0; s[i]; i++) {
		if (s[i] == 'R') {
			r++;
		} else {
			// RȊO̕rrɈꎞۑĂ
			rr = s[i];
			s[i]=='G' ? g++ : w++;
		}
		if (w < g || g < r) {
			return false;
		}
	}
	// RȊO̍Ō̕GłȂƂ
	if (rr != 'G' || g != r) {
		return false;
	}
	return true;
}

int main () {
	// W
	int n = 0;
	std::cin >> n;
	char s[1010]={};
	for (int i=0; i<n; i++) {
		std::cin >> s;
		
	// p^[蓾̂ł邩Ȃ
	std::cout << (judge(s) == true ? "possible" : "impossible") << std::endl;
	}
	
	return 0;
	
}
0