結果

問題 No.154 市バス
ユーザー furafyfurafy
提出日時 2015-05-26 05:09:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 909 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 58,484 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 08:32:33
合計ジャッジ時間 1,155 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstring>
#include <stack>

using namespace std;

bool judge(string);

int main(int argc, char *argv[]) {
	int T;
	string pattern;
	cin >> T;
	for (int i = 0; i < T; i++) {
		cin >> pattern;
		cout << (judge(pattern) ? "possible" : "impossible") << endl;
	}
}
bool judge(string s) {
	int numOfWhite = 0;
	int numOfGreen = 0;
	int lastW = -1;
	int lastG = -1;
	int len = s.length();
	char *c = (char *)malloc(sizeof(char) * len + 1);
	strcpy(c, s.c_str());
	for (int i = 0; i < len; i++) {
		if (c[i] == 'W') {
			numOfWhite++;
			lastW = i;
		} else if (c[i] == 'G') {
			if (numOfWhite < 1) {
				return false;
			}
			numOfGreen++;
			lastG = i;
		} else {
			if (numOfGreen > 0) {
				numOfWhite--;
				numOfGreen--;
			} else {
				return false;
			}
		}
	}
	if (numOfGreen != 0) {
		return false;
	}
	if (lastW > lastG) {
		return false;
	}
	return true;
}
0