結果

問題 No.154 市バス
ユーザー tottoripapertottoripaper
提出日時 2015-03-04 19:27:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,160 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 57,036 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 08:22:31
合計ジャッジ時間 1,126 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// ナニソレイミワカンナイ

#include <iostream>
#include <cstring>

std::string S;
int L;

int count(char c){
    int res = 0;
    for(int i=0;i<L;i++){
        if(S[i] == c){res++;}
    }
    return res;
}

int max(char c){
    for(int i=L-1;i>=0;i--){
        if(S[i] == c){return i;}
    }
    return -1;
}

int main(){
    int T;
    std::cin >> T;
    
    while(T--){
        std::cin >> S;

        L = S.size();

        bool can = true;
        if(count('R') == 0){
            can = false;
        }else{
            int w = 0, g = 0, r = 0;
            while(r < L && S[r] != 'R'){r++;}
            
            for(;r<L;){
                while(w < L && S[w] != 'W'){w++;}
                while(g < L && S[g] != 'G'){g++;}

                if(w == L || g == L || w > g || g > r){can = false; break;}
                r++;
                while(r < L && S[r] != 'R'){r++;}
                w++; g++;
            }

            int g_mx = max('G');
            for(int i=g_mx+1;i<L;i++){
                if(S[i] == 'W'){can = false; break;}
            }
        }

        std::cout << (can ? "possible" : "impossible") << std::endl;
    }
}
0