結果

問題 No.154 市バス
ユーザー Konton7Konton7
提出日時 2020-01-18 18:16:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,477 bytes
コンパイル時間 2,302 ms
コンパイル使用メモリ 204,284 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 08:01:24
合計ジャッジ時間 3,411 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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