結果

問題 No.154 市バス
ユーザー lowrlowr
提出日時 2018-11-02 13:22:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 981 bytes
コンパイル時間 1,839 ms
コンパイル使用メモリ 169,736 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 21:16:03
合計ジャッジ時間 2,871 ms
ジャッジサーバーID
(参考情報)
judge8 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

int main() {
    int t;
    std::cin >> t;
    while (t--) {
        std::string s;
        std::cin >> s;
        if (s[s.size() - 1] != 'R' || s[s.size() - 2] != 'G') {
            std::cout << "impossible" << std::endl;
            continue;
        }
        bool flg = true;
        int a = 0, w = 0;
        std::deque<int> q;
        for (auto c : s) {
            switch (c) {
                case 'W':
                w++;
                break;
                case 'G':
                q.push_back(1);
                a = std::max(a, (int)q.size());
                break;
                case 'R':
                if (q.size() == 0) {
                    goto g;
                } else {
                    q.pop_back();
                }
            }
        }
        std::cout << (q.size() == 0 && w >= a ? "possible" : "impossible") << std::endl;
        continue;
g:
        std::cout << "impossible" << std::endl;
    }
    return 0;
}
0