結果

問題 No.154 市バス
ユーザー cherrypi59cherrypi59
提出日時 2019-04-21 19:55:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 163,708 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 12:16:06
合計ジャッジ時間 2,312 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int T; cin >> T;

    while(T--){
        string S; cin >> S;

        int cr = 0, cg = 0, cw = 0;
        bool ok = true;
        reverse(S.begin(), S.end());
        for(auto c : S){
            if(c=='R') cr++;
            else if(c=='G'){
                if(cr==0) ok = false;
                else cr--, cg++;
            }
            else{
                if(cg==0 and cw == 0) ok = false;
                else if(cg) cg--, cw++;
            }
        }
        
        if(cr or cg) ok = false;
        
        if(ok) cout << "possible" << endl;
        else cout << "impossible" << endl;
    }
    
    return 0;
}
0