結果

問題 No.154 市バス
コンテスト
ユーザー furafy
提出日時 2015-05-26 05:01:01
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 898 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 596 ms
コンパイル使用メモリ 75,116 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-30 15:55:22
合計ジャッジ時間 1,762 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 7 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'bool judge(std::string)':
main.cpp:49:9: warning: 'lastW' may be used uninitialized [-Wmaybe-uninitialized]
   49 |         if (lastW > lastG) {
      |         ^~
main.cpp:22:13: note: 'lastW' was declared here
   22 |         int lastW;
      |             ^~~~~
main.cpp:49:9: warning: 'lastG' may be used uninitialized [-Wmaybe-uninitialized]
   49 |         if (lastW > lastG) {
      |         ^~
main.cpp:23:13: note: 'lastG' was declared here
   23 |         int lastG;
      |             ^~~~~

ソースコード

diff #
raw source code

#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;
	int lastG;
	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