結果

問題 No.38 赤青白ブロック
ユーザー GOTKAKO
提出日時 2025-05-22 19:15:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 95 ms / 5,000 ms
コード長 1,288 bytes
コンパイル時間 2,900 ms
コンパイル使用メモリ 198,696 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-22 19:15:44
合計ジャッジ時間 3,847 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int Kr,Kb; cin >> Kr >> Kb;
    string s; cin >> s;
    vector<int> RB;
    for(int i=0; i<30; i++) if(s.at(i) != 'W') RB.push_back(i);

    int n2 = 1<<20,n = 20,answer = 10;
    for(int S=0; S<n2; S++){
        int siz = 30-__popcount(S);
        if(answer >= siz) continue;

        vector<bool> NG(30);
        string now = "";
        for(int i=0; i<n; i++) if(S&(1<<i)) NG.at(RB.at(i)) = true;
        for(int i=0; i<30; i++) if(!NG.at(i)) now += s.at(i);
        
        bool ok = true;
        for(int i=0; i<siz; i++){
            if(now.at(i) == 'W') continue;
            if(now.at(i) == 'B'){
                int check = i-Kb;
                if(check >= 0 && now.at(check) == 'B') ok = false;
                check = i+Kb;
                if(check < siz && now.at(check) == 'B') ok = false;
            }
            else{
                int check = i-Kr;
                if(check >= 0 && now.at(check) == 'R') ok = false;
                check = i+Kr;
                if(check < siz && now.at(check) == 'R') ok = false;
            }
            if(!ok) break;
         }
        if(ok) answer = max(answer,siz);
    }
    cout << answer << endl;
}
0