結果

問題 No.38 赤青白ブロック
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-09-29 21:31:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,041 ms / 5,000 ms
コード長 1,449 bytes
コンパイル時間 1,671 ms
コンパイル使用メモリ 174,348 KB
実行使用メモリ 22,956 KB
最終ジャッジ日時 2023-08-25 01:18:37
合計ジャッジ時間 8,080 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,376 KB
testcase_01 AC 96 ms
5,672 KB
testcase_02 AC 440 ms
12,748 KB
testcase_03 AC 218 ms
8,380 KB
testcase_04 AC 52 ms
4,732 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 604 ms
15,892 KB
testcase_07 AC 861 ms
20,440 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 427 ms
12,192 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 111 ms
5,784 KB
testcase_16 AC 106 ms
5,840 KB
testcase_17 AC 191 ms
7,628 KB
testcase_18 AC 33 ms
4,376 KB
testcase_19 AC 54 ms
4,676 KB
testcase_20 AC 225 ms
8,372 KB
testcase_21 AC 339 ms
10,632 KB
testcase_22 AC 59 ms
4,652 KB
testcase_23 AC 15 ms
4,376 KB
testcase_24 AC 1,041 ms
22,956 KB
testcase_25 AC 379 ms
11,516 KB
testcase_26 AC 68 ms
4,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        auto i = vs.begin();
        os << "[" << *i;
        for (++i; i != vs.end(); ++i) os << " " << *i;
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int Kr, Kb;
    string S;
    void input() {
        cin >> Kr >> Kb;
        cin >> S;
    }

    bool check(const string& s) {
        int n = s.size();
        for (int i = 0; i < n; i++) {
            if (s[i] == 'W') continue;
            int k = (s[i] == 'R' ? Kr : Kb);
            if (i - k >= 0 && s[i - k] == s[i]) return false;
        }
        return true;
    }

    map<string, int> cache;
    int dfs(const string& s) {
        if (cache.count(s)) return cache[s];
        //cout << s << endl;
        int n = s.size();
        if (check(s)) return n;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == 'W') continue;
            ans = max(ans, dfs(s.substr(0, i) + s.substr(i + 1, n - i - 1)));
        }
        return cache[s] = ans;
    }

    void solve() {
        cout << dfs(S) << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0