結果

問題 No.38 赤青白ブロック
ユーザー cormorancormoran
提出日時 2016-09-29 22:13:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 1,272 bytes
コンパイル時間 1,915 ms
コンパイル使用メモリ 157,016 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-25 01:18:53
合計ジャッジ時間 2,988 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 14 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 4 ms
4,384 KB
testcase_17 AC 2 ms
4,388 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 42 ms
4,384 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, j) for(int i=0; i < (int)(j); i++)

template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }

class Solver {
  public:
    int Kr, Kb;
    int maxi;
    bool check(const string &s) {
        auto f = [&](int i, int w, char c) {
            int l = i - w, r = i + w;
            if(0 <= l and s[l] == c) return false;
            if(r < s.size() and s[r] == c) return false;
            return true;
        };
        rep(i, s.size()) {
            if(s[i] == 'R' and !f(i, Kr, 'R')) return false;
            if(s[i] == 'B' and !f(i, Kb, 'B')) return false;
        }
        return true;
    }

    int rec(const string &s, int i) {
        if(s.size() <= maxi) return 0;
        if(i >= s.size()) return check(s) ? s.size() : 0;
        if(s[i] == 'W') return rec(s, i + 1);
        int ret = max(rec(s, i + 1), rec(s.substr(0, i) + s.substr(i + 1), i));
        set_max(maxi, ret);
        return ret;
    }
    
    bool solve() {
        cin >> Kr >> Kb;
        string S; cin >> S;
        maxi = 0;
        cout << rec(S, 0) << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0