結果

問題 No.154 市バス
ユーザー potoooooooo
提出日時 2019-01-18 00:41:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 942 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 167,248 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-01 10:12:14
合計ジャッジ時間 2,655 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n; cin >> n;
    for (int ni = 0; ni < n; ni++) {
        string s; cin >> s;
        bool ans = true;
        int rcount = 0; int gcount = 0;
        int wrequire = 0; bool wflag = false;
        for (int i = s.size()-1; i >= 0; i--) {
            if (s[i] == 'R') rcount++;
            if (s[i] == 'G') gcount++;
            if (rcount < gcount) ans *= false;
            if (rcount > 0 && gcount > 0) {
                wrequire++; wflag = true;
                rcount--; gcount--;
            }
            if (s[i] == 'W') {
                if (!wflag) ans *= false;
                else {
                    wrequire = max(wrequire-1, 0);
                }
            }
        }
        if (!wflag || wrequire > 0 || rcount > 0 || gcount > 0) ans *= false;
        if (ans) cout << "possible" << endl;
        else cout << "impossible" << endl;
    }
    return 0;
}
0