結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 245 ms
5,248 KB
testcase_01 AC 252 ms
5,376 KB
testcase_02 AC 247 ms
5,376 KB
testcase_03 AC 57 ms
5,376 KB
testcase_04 AC 229 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 651 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int max(char)’:
main.cpp:28:1: warning: control reaches end of non-void function [-Wreturn-type]
   28 | }
      | ^

ソースコード

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;}
    }
}

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