結果

問題 No.154 市バス
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-01-19 12:58:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,174 bytes
コンパイル時間 919 ms
コンパイル使用メモリ 105,164 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 22:37:52
合計ジャッジ時間 1,873 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

int main(){

    int T, g, r;
    string S;
    cin >> T;

    while(T){
        cin >> S;
        g = 0; r=0;
        for (int i=0; i<S.size(); i++) if (S[i] == 'R') r++;
        if (S.back() != 'R'){
            cout << "impossible" << '\n';
            T--;
            continue;
        }

        bool f=1;
        for (int i=0; i<S.size(); i++){
            if (S[i] == 'G') g++;
            else if (S[i] == 'R'){
                r--;
                if (g == 0){
                    T--;
                    cout << "impossible" << '\n';
                    f = 0;
                    break;
                }
                else g--;
            }
            else if (S[i] == 'W' && r == 1 && g == 1){
                cout << "impossible" << '\n';
                f = 0;
                break;
            }
        }

        if (f) cout << (g == 0 ? "possible" : "impossible") << '\n';
        T--;
    }

    return 0;
}
0