結果

問題 No.154 市バス
ユーザー LunaLuna
提出日時 2019-03-07 10:43:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,100 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 64,396 KB
実行使用メモリ 5,608 KB
最終ジャッジ日時 2023-09-05 19:21:44
合計ジャッジ時間 1,301 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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


bool solve(const std::string& s) {
    int cntR{}, cntG{}, cntW{};

    for (const auto c : s) {
        if (c == 'R') {
            cntR++;
        }

        if (c == 'G') {
            if (cntR >= 1) {
                cntG++;
                cntR--;
            } else {
                return false;
            }
        }

        if (c == 'W') {
            if (cntG >= 1) {
                cntW++;
                cntG--;
            } else if (cntW >=1) {
                cntW++;
            } else {
                return false;
            }
        }

        if (cntR == 0 && cntG == 0) {
            return true;
        }
    }
    return false;
}


int main(int argc, char const* argv[]) {
    int T;
    std::cin >> T;

    std::vector<std::string> s(T);
    for (int i = 0; i < T; i++) {
        std::cin >> s[i];
        std::reverse(s[i].begin(), s[i].end());
    }

    for (int i = 0; i < T; i++) {
        std::cout << (solve(s[i]) ? "possible" : "impossible") << std::endl;
    }
    return 0;
}
0