結果

問題 No.38 赤青白ブロック
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-20 00:40:46
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 256 ms / 5,000 ms
コード長 1,118 bytes
コンパイル時間 1,102 ms
コンパイル使用メモリ 143,080 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-29 02:37:31
合計ジャッジ時間 8,397 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 246 ms
6,812 KB
testcase_01 AC 200 ms
6,940 KB
testcase_02 AC 192 ms
6,940 KB
testcase_03 AC 210 ms
6,940 KB
testcase_04 AC 201 ms
6,944 KB
testcase_05 AC 256 ms
6,944 KB
testcase_06 AC 193 ms
6,944 KB
testcase_07 AC 197 ms
6,940 KB
testcase_08 AC 252 ms
6,944 KB
testcase_09 AC 218 ms
6,944 KB
testcase_10 AC 246 ms
6,940 KB
testcase_11 AC 246 ms
6,944 KB
testcase_12 AC 212 ms
6,940 KB
testcase_13 AC 248 ms
6,944 KB
testcase_14 AC 217 ms
6,940 KB
testcase_15 AC 244 ms
6,944 KB
testcase_16 AC 173 ms
6,940 KB
testcase_17 AC 202 ms
6,940 KB
testcase_18 AC 241 ms
6,944 KB
testcase_19 AC 215 ms
6,940 KB
testcase_20 AC 211 ms
6,940 KB
testcase_21 AC 187 ms
6,944 KB
testcase_22 AC 220 ms
6,944 KB
testcase_23 AC 238 ms
6,940 KB
testcase_24 AC 190 ms
6,944 KB
testcase_25 AC 229 ms
6,940 KB
testcase_26 AC 226 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>

using namespace std;

int r, b;

bool check(string &T){
    for (int i=0; i<30; i++){
        if (T[i] == 'R'){
            if ((i-r >= 0 && T[i-r] == 'R') || (i+r < T.size() && T[i+r] == 'R')) return 0;
        }
        else if (T[i] == 'B'){
            if ((i-b >= 0 && T[i-b] == 'B') || (i+b < T.size() && T[i+b] == 'B')) return 0;
        }  
    }
    return 1;
}

int main(){

    int cnt, mx=0;
    string S, T;
    cin >> r >> b >> S;

    for (int i=(1<<20)-1; i>=0; i--){
        T = "";
        cnt = 0;
        for (int j=0; j<20; j++){
            while (j+cnt < 30 && S[j+cnt] == 'W'){
                T += 'W';
                cnt++;
            }   
            if (i & (1<<j)) T += S[j+cnt];
        }
        while (20+cnt < 30 && S[20+cnt] == 'W'){
            T += 'W';
            cnt++;
        }
        if (check(T)) mx = max(mx, (int)T.size());
    }

    cout << mx << endl;

    return 0;
}
0