結果

問題 No.154 市バス
ユーザー mocobtmocobt
提出日時 2018-06-09 20:34:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,180 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 64,408 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 02:22:02
合計ジャッジ時間 1,360 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;

auto T=0;

void input(){
    cin >> T;
}

void solve(){
    for(int i=0; i<T; i++){
        string s;
        cin >> s;
        if(s.size()<3){
            cout << "impossible" << endl;
            continue;
        }
        
        auto r_cnt = 0, g_cnt = 0, w_cnt = 0;
        bool ans = true;
        char prev = 'N';
        for(int j=0;j<s.size();j++){
            switch(s[j]){
                case 'R':
                    prev = 'R';
                    r_cnt++;
                    break;
                case 'G':
                    if(prev!='W'&&prev!='N'){
                        ans = false;
                        break;
                    }
                    prev = 'G';
                    g_cnt++;
                    break;
                case 'W':
                    prev = 'W';
                    w_cnt++;
                    break;
            }
            if(!(w_cnt>=g_cnt&&g_cnt>=r_cnt)) ans = false;
        }
        if(g_cnt!=r_cnt) ans = false;

        if(ans) cout<<"possible" << endl;
        else cout << "impossible" << endl;
    }
}

int main(){
    input();
    solve();
}
0