結果

問題 No.38 赤青白ブロック
ユーザー face4face4
提出日時 2019-02-21 11:52:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 540 ms / 5,000 ms
コード長 1,036 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 73,460 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 23:23:37
合計ジャッジ時間 16,386 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 535 ms
4,380 KB
testcase_01 AC 493 ms
4,380 KB
testcase_02 AC 490 ms
4,384 KB
testcase_03 AC 505 ms
4,380 KB
testcase_04 AC 498 ms
4,380 KB
testcase_05 AC 540 ms
4,380 KB
testcase_06 AC 493 ms
4,380 KB
testcase_07 AC 488 ms
4,380 KB
testcase_08 AC 536 ms
4,380 KB
testcase_09 AC 507 ms
4,380 KB
testcase_10 AC 525 ms
4,384 KB
testcase_11 AC 527 ms
4,380 KB
testcase_12 AC 495 ms
4,376 KB
testcase_13 AC 535 ms
4,376 KB
testcase_14 AC 504 ms
4,380 KB
testcase_15 AC 532 ms
4,380 KB
testcase_16 AC 472 ms
4,380 KB
testcase_17 AC 495 ms
4,376 KB
testcase_18 AC 534 ms
4,380 KB
testcase_19 AC 500 ms
4,380 KB
testcase_20 AC 508 ms
4,380 KB
testcase_21 AC 490 ms
4,376 KB
testcase_22 AC 515 ms
4,384 KB
testcase_23 AC 522 ms
4,376 KB
testcase_24 AC 492 ms
4,380 KB
testcase_25 AC 512 ms
4,376 KB
testcase_26 AC 510 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

int main(){
    int r, b;
    string s;
    cin >> r >> b >> s;
    auto check = [=](string t)->bool{
        int n = t.length();
        for(int i = 0; i < n; i++){
            if(t[i] == 'R'){
                if(i-r >= 0 && t[i-r] == 'R')    return false;
                if(i+r < n && t[i+r] == 'R')    return false;
            }
            if(t[i] == 'B'){
                if(i-b >= 0 && t[i-b] == 'B')    return false;
                if(i+b < n && t[i+b] == 'B')    return false;
            }
        }
        return true;
    };
    vector<int> v;
    int ans = 10;
    for(int i = 0; i < 30; i++) if(s[i] != 'W') v.push_back(i);
    for(int i = 0; i < 1<<20; i++){
        vector<bool> use(30, true);
        for(int j = 0; j < 20; j++) if((i>>j)&1)    use[v[j]] = false;
        string t = "";
        for(int j = 0; j < 30; j++) if(use[j])  t += s.substr(j,1);
        if(check(t))    ans = max(ans, (int)t.length());
    }
    cout << ans << endl;
    return 0;
}
0