結果

問題 No.154 市バス
ユーザー fantasiabaeticafantasiabaetica
提出日時 2018-09-25 12:14:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 57,108 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 22:12:57
合計ジャッジ時間 2,345 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
using namespace std;

int solve(string str){
    // 最後から2本目より前のバスが走っている可能性のある系統の最大数
    int max_n = 0;
    // 最後から一本目が走ったが、最後の一本は走っていない系統の数
    int last = 0;
    FOR(j, 0, str.size()){
        string c = str.substr(j, 1);
        if (c == "W"){
            max_n++;
        } else if (c == "G"){
            max_n --;
            if (max_n < 0) return 0;
            last += 1;
        } else{
            last--;
            if (last < 0) return 0;
        }
    }
    // lastが0かつRで終わる場合のみあり得るパターン
    if (last == 0 && str.substr(str.size() - 1, 1) == "R"){
        return 1;
    } else {
        return 0;
    }
}

int main(){
    int t;
    cin >> t;
    FOR(i, 0, t){
        string str;
        cin >> str;
        int if_possible = solve(str);
        if(if_possible){
            cout << "possible" << endl;
        } else {
            cout << "impossible" << endl;
        }
    }

    return 0;
}
0