結果

問題 No.38 赤青白ブロック
ユーザー PachicobuePachicobue
提出日時 2017-07-03 16:41:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,564 bytes
コンパイル時間 1,655 ms
コンパイル使用メモリ 167,188 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 14:37:03
合計ジャッジ時間 6,584 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 140 ms
6,944 KB
testcase_03 AC 140 ms
6,940 KB
testcase_04 WA -
testcase_05 AC 151 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 139 ms
6,940 KB
testcase_08 AC 152 ms
6,944 KB
testcase_09 WA -
testcase_10 AC 152 ms
6,940 KB
testcase_11 AC 151 ms
6,944 KB
testcase_12 AC 142 ms
6,944 KB
testcase_13 AC 152 ms
6,944 KB
testcase_14 AC 139 ms
6,944 KB
testcase_15 AC 150 ms
6,940 KB
testcase_16 AC 135 ms
6,944 KB
testcase_17 AC 146 ms
6,940 KB
testcase_18 AC 147 ms
6,940 KB
testcase_19 AC 146 ms
6,940 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 151 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 145 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

constexpr int MAXIMUM = 1 << 10;

int main()
{
    int kr, kb;
    cin >> kr >> kb;
    string s;
    cin >> s;
    vector<int> reds;
    vector<int> blues;
    for (ll i = 0; i < 30; i++) {
        if (s[i] == 'R') {
            reds.push_back(i);
        } else if (s[i] == 'B') {
            blues.push_back(i);
        }
    }

    int mini = 100;
    for (int i = 0; i <= MAXIMUM; i++) {
        for (int j = 0; j <= MAXIMUM; j++) {
            bool ok[30];
            fill(ok, ok + 30, true);
            int numi = i;
            int popi = 0;
            int indi = 0;
            while (numi > 0) {
                if (numi % 2 == 1) {
                    popi++;
                    ok[reds[indi]] = false;
                }
                indi++;
                numi /= 2;
            }
            int numj = j;
            int popj = 0;
            int indj = 0;
            while (numj > 0) {
                if (numi % 2 == 1) {
                    popj++;
                    ok[blues[indj]] = false;
                }
                indj++;
                numj /= 2;
            }
            string str;
            for (ll p = 0; p < 30; p++) {
                if (ok[p]) {
                    str.push_back(s[p]);
                }
            }
            bool flag = true;
            for (int p = 0; p < str.size(); p++) {
                if (str[p] == 'R') {
                    if (p >= kr and str[p - kr] == 'R') {
                        flag = false;
                        break;
                    }
                } else if (str[p] == 'B') {
                    if (p >= kb and str[p - kb] == 'B') {
                        flag = false;
                        break;
                    }
                }
            }
            if (flag) {
                mini = min(mini, popi + popj);
            }
        }
    }
    cout << 30 - mini << endl;

    return 0;
}
0