結果

問題 No.38 赤青白ブロック
ユーザー MisterMister
提出日時 2020-08-27 17:29:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 236 ms / 5,000 ms
コード長 1,058 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 76,016 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-07 16:59:28
合計ジャッジ時間 7,741 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 228 ms
4,380 KB
testcase_01 AC 198 ms
4,376 KB
testcase_02 AC 202 ms
4,380 KB
testcase_03 AC 208 ms
4,380 KB
testcase_04 AC 202 ms
4,376 KB
testcase_05 AC 235 ms
4,380 KB
testcase_06 AC 198 ms
4,376 KB
testcase_07 AC 199 ms
4,376 KB
testcase_08 AC 236 ms
4,376 KB
testcase_09 AC 223 ms
4,384 KB
testcase_10 AC 228 ms
4,384 KB
testcase_11 AC 230 ms
4,376 KB
testcase_12 AC 210 ms
4,380 KB
testcase_13 AC 227 ms
4,376 KB
testcase_14 AC 219 ms
4,376 KB
testcase_15 AC 231 ms
4,376 KB
testcase_16 AC 191 ms
4,376 KB
testcase_17 AC 206 ms
4,376 KB
testcase_18 AC 231 ms
4,380 KB
testcase_19 AC 202 ms
4,380 KB
testcase_20 AC 210 ms
4,376 KB
testcase_21 AC 193 ms
4,380 KB
testcase_22 AC 230 ms
4,376 KB
testcase_23 AC 221 ms
4,380 KB
testcase_24 AC 199 ms
4,376 KB
testcase_25 AC 217 ms
4,380 KB
testcase_26 AC 210 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

bool judge(const std::string& s, int kr, int kb) {
    int n = s.length();
    for (int i = 0; i < n; ++i) {
        switch (s[i]) {
            case 'R':
                if (i + kr < n && s[i + kr] == 'R') return false;
                break;
            case 'B':
                if (i + kb < n && s[i + kb] == 'B') return false;
                break;
        }
    }
    return true;
}

void solve() {
    int kr, kb;
    std::string s;
    std::cin >> kr >> kb >> s;

    int ans = 0;
    for (int b = 0; b < (1 << 20); ++b) {
        std::string t;
        int itr = 0;
        for (char c : s) {
            if (c == 'R' || c == 'B') {
                if ((b >> itr++) & 1) continue;
            }
            t.push_back(c);
        }

        if (!judge(t, kr, kb)) continue;
        ans = std::max(ans, (int)t.length());
    }

    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}
0