結果

問題 No.154 市バス
ユーザー tottoripapertottoripaper
提出日時 2015-03-04 18:56:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 1,351 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 53,980 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 09:47:00
合計ジャッジ時間 1,925 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>

std::string S;
bool used[1000];
int L;

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

int find(char c, int ub){
    for(int i=0;i<ub;i++){
        if(S[i] == c && !used[i]){
            return i;
        }
    }
    return -1;
}

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();

        for(int i=0;i<L;i++){used[i] = false;}

        bool can = true;

        if(count('R') != count('G') ||
           L < count('R') * 3){
            can = false;
        }else{
            for(int i=0;i<L;i++){
                if(S[i] == 'R'){
                    int g_index = find('G', i);
                    if(g_index == -1){can = false; break;}
                    used[g_index] = true;
                    int w_index = find('W', g_index);
                    if(w_index == -1){can = false; break;}
                    used[w_index] = true;
                }
            }

            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