結果

問題 No.154 市バス
ユーザー Konton7
提出日時 2020-01-18 18:16:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,477 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 198,576 KB
最終ジャッジ日時 2025-01-08 20:08:09
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 7 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define DEBUG

void is_possible(string s){
    stack<int> bus;
    reverse(s.begin(), s.end());
    string result = "possible";
    // cout << s << endl;
    bool white_ok = false;
    rep(i, s.length()){
        if (white_ok){

            if (s[i] == 'R')
                bus.push(1);
            else if (s[i] == 'G')
                if (!bus.empty())
                    bus.pop();
                else{
                    result = "impossible";
                    break;
                }
        }
        else{
            
            if (s[i] == 'R'){
                bus.push(1);
                
            }
            else if (s[i] == 'G')
                if (!bus.empty()){
                    bus.pop();
                    white_ok = true;
                }
                else{
                    result = "impossible";
                    break;
                }
            else if (s[i] == 'W'){
                    result = "impossible";
                    break;
                }
        }
    }
    
    if (!bus.empty())
        result = "impossible";
    
    cout << result << endl;
    return;
}

int main()
{
    int n;
    string s;
    cin >> n;
    
    rep(i, n){
        cin >> s;
        is_possible(s);
    }        
        
    
    
    return 0;
}
0