結果

問題 No.154 市バス
ユーザー yosupotyosupot
提出日時 2015-02-17 23:29:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 69,544 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 08:49:09
合計ジャッジ時間 1,547 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//#define NDEBUG
 
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <cassert>
#include <numeric>

using namespace std;
typedef long long ll;

bool solve() {
    string s;
    cin >> s;
    int n = s.size();
    reverse(s.begin(), s.end());
    int d[3] = {};
    bool f = false;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            d[0]++;
        } else if (s[i] == 'G') {
            if (!d[0]) return false;
            d[0]--;
            d[1]++;
        } else {
            if (!f && !d[1]) return false;
            f = true;
            if (d[1]) {
                d[1]--;
            }
            d[2]++;
        }
    }
    if (d[0] || d[1]) return false;
    return true;
}

int main() {
    int t = 0;
    cin >> t;
    for (int i = 0; i < t; i++) {
        if (solve()) {
            cout << "possible" << endl;
        } else {
            cout << "impossible" << endl;
        }
    }
    return 0;
}
0