結果

問題 No.38 赤青白ブロック
ユーザー face4face4
提出日時 2019-02-21 11:52:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 503 ms / 5,000 ms
コード長 1,036 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 73,856 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 16:29:33
合計ジャッジ時間 14,869 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 486 ms
5,248 KB
testcase_01 AC 451 ms
5,376 KB
testcase_02 AC 458 ms
5,376 KB
testcase_03 AC 460 ms
5,376 KB
testcase_04 AC 466 ms
5,376 KB
testcase_05 AC 503 ms
5,376 KB
testcase_06 AC 444 ms
5,376 KB
testcase_07 AC 446 ms
5,376 KB
testcase_08 AC 491 ms
5,376 KB
testcase_09 AC 463 ms
5,376 KB
testcase_10 AC 483 ms
5,376 KB
testcase_11 AC 483 ms
5,376 KB
testcase_12 AC 457 ms
5,376 KB
testcase_13 AC 485 ms
5,376 KB
testcase_14 AC 481 ms
5,376 KB
testcase_15 AC 485 ms
5,376 KB
testcase_16 AC 436 ms
5,376 KB
testcase_17 AC 448 ms
5,376 KB
testcase_18 AC 477 ms
5,376 KB
testcase_19 AC 454 ms
5,376 KB
testcase_20 AC 465 ms
5,376 KB
testcase_21 AC 445 ms
5,376 KB
testcase_22 AC 489 ms
5,376 KB
testcase_23 AC 477 ms
5,376 KB
testcase_24 AC 450 ms
5,376 KB
testcase_25 AC 481 ms
5,376 KB
testcase_26 AC 466 ms
5,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