結果

問題 No.38 赤青白ブロック
ユーザー tottoripapertottoripaper
提出日時 2014-11-24 02:55:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 469 ms / 5,000 ms
コード長 1,389 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 71,356 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 00:57:50
合計ジャッジ時間 13,870 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 442 ms
4,380 KB
testcase_01 AC 412 ms
4,380 KB
testcase_02 AC 412 ms
4,376 KB
testcase_03 AC 440 ms
4,376 KB
testcase_04 AC 426 ms
4,376 KB
testcase_05 AC 453 ms
4,380 KB
testcase_06 AC 420 ms
4,376 KB
testcase_07 AC 411 ms
4,380 KB
testcase_08 AC 452 ms
4,380 KB
testcase_09 AC 412 ms
4,376 KB
testcase_10 AC 469 ms
4,376 KB
testcase_11 AC 460 ms
4,376 KB
testcase_12 AC 436 ms
4,376 KB
testcase_13 AC 448 ms
4,376 KB
testcase_14 AC 443 ms
4,376 KB
testcase_15 AC 431 ms
4,376 KB
testcase_16 AC 412 ms
4,376 KB
testcase_17 AC 423 ms
4,376 KB
testcase_18 AC 431 ms
4,380 KB
testcase_19 AC 427 ms
4,376 KB
testcase_20 AC 416 ms
4,376 KB
testcase_21 AC 397 ms
4,376 KB
testcase_22 AC 422 ms
4,376 KB
testcase_23 AC 463 ms
4,376 KB
testcase_24 AC 415 ms
4,380 KB
testcase_25 AC 442 ms
4,376 KB
testcase_26 AC 423 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

int main(){
    int r, b;
    std::cin >> r >> b;

    std::string S;
    std::cin >> S;

    std::vector<int> rs, bs;
    for(int i=0;i<30;i++){
        if(S[i] == 'R'){
            rs.push_back(i);
        }else if(S[i] == 'B'){
            bs.push_back(i);
        }
    }

    int res = 0;
    for(int i=0;i<1<<10;i++){
        for(int j=0;j<1<<10;j++){
            std::vector<int> indices;
            for(int k=0;k<10;k++){
                if(i >> k & 1){indices.push_back(rs[k]);}
                if(j >> k & 1){indices.push_back(bs[k]);}
            }

            std::sort(indices.rbegin(), indices.rend());

            std::string s = S;
            for(int index : indices){
                s.erase(s.begin() + index);
            }

            int l = s.size();
            bool f = true;
            for(int k=0;k<l;k++){
                if(s[k] == 'R' && (k-r >= 0 && s[k-r] == 'R' || k+r < l && s[k+r] == 'R')){
                    f = false;
                    break;
                }else if(s[k] == 'B' && (k-b >= 0 && s[k-b] == 'B' || k+b < l && s[k+b] == 'B')){
                    f = false;
                    break;
                }
            }

            if(f){res = std::max(res, l);}
        }
    }

    std::cout << res << std::endl;
}
0