結果

問題 No.154 市バス
ユーザー ant2357ant2357
提出日時 2016-06-12 12:44:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,576 bytes
コンパイル時間 1,025 ms
コンパイル使用メモリ 97,496 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 09:34:50
合計ジャッジ時間 1,740 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <numeric>

#define REP(i, n) for(int i = 0;i < (n); i++)
#define REP2(i, x, n) for(int i = (x); i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

using namespace std;



//================================================

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int T;
	cin >> T;
	vector<string>ans(T);

	string S;

	REP(i, T) {
		cin >> S;

		bool flag = false;

		int wCount = 0, gCount = 0, rCount = 0;
		int posW = -1,  posG = -1,  posR = -1;

		REP(j, S.size()) {
			if (S[j] == 'W') {
				wCount++;
				posW = j;
			} else if (S[j] == 'G') {

				if (wCount == 0) {
					ans[i] = "impossible";
					flag = true;
				} else { 
					wCount--; gCount++;
					posG = j;
				}

			} else  if (S[j] == 'R') {

				if (gCount == 0) {
					ans[i] = "impossible";
					flag = true;
				} else { 
					gCount--; rCount++;
					posR = j;
				}

			}

			if (flag) break;
		}

		if (flag) continue;

		if (gCount != 0 || rCount == 0) {
			ans[i] = "impossible";
		} else if (posW < posG && posG < posR) {
			ans[i] = "possible";
		} else {
			ans[i] = "impossible";
		}
	}

	REP(i, T) cout << ans[i] << "\n";
	return 0;
}
0