結果

問題 No.154 市バス
ユーザー face4face4
提出日時 2018-08-09 10:26:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 837 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 65,288 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 11:58:41
合計ジャッジ時間 1,828 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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

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

        for(int i = s[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