結果

問題 No.154 市バス
コンテスト
ユーザー masa
提出日時 2015-02-18 00:11:13
言語 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  
実行時間 -
コード長 847 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 640 ms
コンパイル使用メモリ 80,024 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-30 15:03:43
合計ジャッジ時間 1,575 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 2 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/vector:69,
                 from main.cpp:3:
In member function 'std::_Bit_reference& std::_Bit_reference::operator=(bool)',
    inlined from 'int main()' at main.cpp:46:12:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_bvector.h:112:7: warning: 'isPossible' may be used uninitialized [-Wmaybe-uninitialized]
  112 |       if (__x)
      |       ^~
main.cpp: In function 'int main()':
main.cpp:19:22: note: 'isPossible' was declared here
   19 |                 bool isPossible;
      |                      ^~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int t, w, g, r;
	string s;

	cin >> t;
	vector<bool> ans(t, false);
	for (int i = 0; i < t; i++) {
		cin >> s;
		int n = s.size();
		bool isPossible;

		w = g = r = 0;
		for (int i = n - 1; i >= 0; i--) {
			isPossible = true;
			if (s[i] == 'W') {
				w++;
			} else if (s[i] == 'G') {
				g++;
				if (g <= w || g > r) {
					isPossible = false;
					break;
				}
			} else if (s[i] == 'R') {
				r++;
				if (r <= g || r <= w) {
					isPossible = false;
					break;
				}
			}
		}
		if (!isPossible) {
			if (w == 0 || r != g) {
				isPossible = false;
			}
		}

		ans[i] = isPossible;
	}

	for (int i = 0; i < t; i++) {
		cout << (ans[i] ? "possible" : "impossible") << endl;
	}
	return 0;
}
0