結果

問題 No.154 市バス
ユーザー rabimea
提出日時 2025-09-26 05:53:54
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 2,980 ms
コンパイル使用メモリ 277,728 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-26 05:53:58
合計ジャッジ時間 4,127 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>

using std::cin, std::cout, std::cerr;
using ll = long long;

bool Solve() {
    std::string s; cin >> s;
    std::ranges::reverse(s);
    int cnt = 0, wcnt = 0; bool white = 0;
    for(char c : s) {
        if(c == 'R') cnt ++;
        else if(c == 'G') {
            if(cnt == 0) return false;
            cnt --;
            wcnt ++;
            white = 1;
        } else {
            if(!white) return false;
            if(wcnt > 0)
                wcnt --;
        }
    }
    return cnt == 0 && wcnt == 0;
}

int main() {
    std::ios::sync_with_stdio(false);
    int T; cin >> T;
    while(T --) {
        cout << (Solve() ? "possible" : "impossible") << '\n';
    }
}
0