結果

問題 No.154 市バス
ユーザー tottoripapertottoripaper
提出日時 2015-03-04 18:33:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,136 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 55,644 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 08:22:04
合計ジャッジ時間 1,814 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 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 ||
           S[L-1] == 'W'){
            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;
                }
            }
        }

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