結果

問題 No.154 市バス
ユーザー Iruyan_ZakIruyan_Zak
提出日時 2016-06-19 17:18:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 808 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 60,848 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 11:47:18
合計ジャッジ時間 1,495 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

string solve(string str){
    # define OK "possible"
    # define NG "impossible"
    int n = str.size(), w=0, g=0, r=0;
    bool running = false;
    reverse(str.begin(), str.end());
    if(str[0] != 'R') return NG;
    for(int i=0; i<n; ++i){
        char c = str[i];
             if(c == 'R') ++r;
        else if(c == 'G'){
            if(--r < 0) return NG;
            running = true;
            ++g;
        }
        else{
            ++w;
            if(!running) return NG;
            if(g>0) --g;
        }
    }
    if(r != 0 || g != 0) return NG;
    return OK;

}

int main(){
    int n;
    cin >> n;
    for(int i=0; i<n; ++i){
        string str;
        cin >> str;
        cout << solve(str) << endl;
    }
}
0