結果

問題 No.38 赤青白ブロック
ユーザー PachicobuePachicobue
提出日時 2017-07-03 16:43:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 294 ms / 5,000 ms
コード長 2,564 bytes
コンパイル時間 1,441 ms
コンパイル使用メモリ 168,364 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-25 01:23:51
合計ジャッジ時間 10,298 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 282 ms
4,376 KB
testcase_01 AC 268 ms
4,376 KB
testcase_02 AC 283 ms
4,376 KB
testcase_03 AC 281 ms
4,376 KB
testcase_04 AC 267 ms
4,376 KB
testcase_05 AC 286 ms
4,380 KB
testcase_06 AC 265 ms
4,376 KB
testcase_07 AC 267 ms
4,376 KB
testcase_08 AC 289 ms
4,380 KB
testcase_09 AC 276 ms
4,376 KB
testcase_10 AC 284 ms
4,380 KB
testcase_11 AC 294 ms
4,388 KB
testcase_12 AC 288 ms
4,380 KB
testcase_13 AC 285 ms
4,380 KB
testcase_14 AC 286 ms
4,376 KB
testcase_15 AC 287 ms
4,376 KB
testcase_16 AC 258 ms
4,376 KB
testcase_17 AC 272 ms
4,380 KB
testcase_18 AC 278 ms
4,380 KB
testcase_19 AC 265 ms
4,380 KB
testcase_20 AC 272 ms
4,380 KB
testcase_21 AC 266 ms
4,376 KB
testcase_22 AC 255 ms
4,380 KB
testcase_23 AC 286 ms
4,376 KB
testcase_24 AC 257 ms
4,380 KB
testcase_25 AC 292 ms
4,384 KB
testcase_26 AC 270 ms
4,380 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 (numj % 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