結果

問題 No.154 市バス
ユーザー face4face4
提出日時 2018-08-09 10:52:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 65,356 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 11:59:02
合計ジャッジ時間 1,619 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
using namespace std;

int main(){
    int t;
    cin >> t;

    string s;
    for(int i = 0; i < t; i++){
        cin >> s;
        bool judge = true;

        int tmp = 0, w = 0, g = 0, bus = 0;
        for(int i = 0; i < s.length(); i++){
            if(s[i] == 'G'){
                tmp++;
                g++;
                if(w < g)   judge = false;
            }else if(s[i] == 'R'){
                tmp--;
                bus++;
                if(tmp < 0) judge = false;
            }else if(s[i] == 'W'){
                w++;
            }
        }

        if(tmp != 0)    judge = false;
        if(w < bus) judge = false;
        if(s[s.length()-1] != 'R')  judge = false;

        for(int i = s.length()-1; i >= 0 && s[i] != 'G'; i--){
            if(s[i] == 'W') judge = false;
        }

        if(judge)   cout << "possible" << endl;
        else        cout << "impossible" << endl;
    }

    return 0;
}
0