結果

問題 No.154 市バス
ユーザー MisterMister
提出日時 2020-04-22 11:22:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 806 ms
コンパイル使用メモリ 75,520 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 10:34:49
合計ジャッジ時間 1,461 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

void solve() {
    std::string s;
    std::cin >> s;
    std::reverse(s.begin(), s.end());

    int wcnt = 0, gcnt = 0, rcnt = 0, gok = 0;
    for (char c : s) {
        if (c == 'W') {
            ++wcnt;
            gok = std::max(0, gok - 1);
        } else if (c == 'G') {
            ++gok;
            ++gcnt;
        } else if (c == 'R') {
            ++rcnt;
        }

        if ((gcnt == 0 && wcnt > 0) || gcnt > rcnt) {
            std::cout << "impossible" << std::endl;
            return;
        }
    }

    std::cout << (gok == 0 && gcnt == rcnt ? "possible" : "impossible")
              << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int q;
    std::cin >> q;
    while (q--) solve();

    return 0;
}
0