結果

問題 No.38 赤青白ブロック
ユーザー kk
提出日時 2021-02-25 16:12:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 246 ms / 5,000 ms
コード長 1,022 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 203,192 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-08 13:51:21
合計ジャッジ時間 9,734 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 236 ms
6,548 KB
testcase_01 AC 202 ms
6,548 KB
testcase_02 AC 229 ms
6,548 KB
testcase_03 AC 215 ms
6,548 KB
testcase_04 AC 206 ms
6,548 KB
testcase_05 AC 239 ms
6,548 KB
testcase_06 AC 208 ms
6,548 KB
testcase_07 AC 218 ms
6,548 KB
testcase_08 AC 245 ms
6,548 KB
testcase_09 AC 214 ms
6,548 KB
testcase_10 AC 224 ms
6,548 KB
testcase_11 AC 238 ms
6,548 KB
testcase_12 AC 233 ms
6,548 KB
testcase_13 AC 235 ms
6,548 KB
testcase_14 AC 234 ms
6,548 KB
testcase_15 AC 246 ms
6,548 KB
testcase_16 AC 193 ms
6,548 KB
testcase_17 AC 219 ms
6,548 KB
testcase_18 AC 229 ms
6,548 KB
testcase_19 AC 211 ms
6,548 KB
testcase_20 AC 230 ms
6,548 KB
testcase_21 AC 217 ms
6,548 KB
testcase_22 AC 229 ms
6,548 KB
testcase_23 AC 231 ms
6,548 KB
testcase_24 AC 206 ms
6,548 KB
testcase_25 AC 242 ms
6,548 KB
testcase_26 AC 227 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int r, b;
  cin >> r >> b;
  string s;
  cin >> s;

  int sub = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] != 'W')
      sub |= 1 << i;
  }

  int ret = 0;
  int mask = sub;
  do {
    string t;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == 'W') t += 'W';
      else if (mask & 1 << i) t += s[i];
    }

    bool ck = true;
    for (int i = 0; i < t.length(); i++) {
      if (t[i] == 'R') {
        if (i-r >= 0 && t[i-r] == 'R') {
          ck = false;
          break;
        }
      } else if (t[i] == 'B') {
        if (i-b >= 0 && t[i-b] == 'B') {
          ck = false;
          break;
        }
      }
    }
    if (ck) {
      int tmp = __builtin_popcountll(mask);
      ret = max(ret, tmp);
    }
    --mask &= sub;
  } while (mask != sub);

  ret += count(s.begin(), s.end(), 'W');
  cout << ret << endl;
  
  return 0;
}
0