結果

問題 No.38 赤青白ブロック
ユーザー d2verbd2verb
提出日時 2017-09-12 23:14:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 333 ms / 5,000 ms
コード長 1,306 bytes
コンパイル時間 3,881 ms
コンパイル使用メモリ 165,608 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 01:25:04
合計ジャッジ時間 8,102 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 215 ms
4,376 KB
testcase_01 AC 184 ms
4,380 KB
testcase_02 AC 131 ms
4,384 KB
testcase_03 AC 254 ms
4,376 KB
testcase_04 AC 323 ms
4,380 KB
testcase_05 AC 237 ms
4,376 KB
testcase_06 AC 131 ms
4,380 KB
testcase_07 AC 135 ms
4,376 KB
testcase_08 AC 162 ms
4,380 KB
testcase_09 AC 142 ms
4,376 KB
testcase_10 AC 232 ms
4,380 KB
testcase_11 AC 215 ms
4,376 KB
testcase_12 AC 246 ms
4,380 KB
testcase_13 AC 333 ms
4,376 KB
testcase_14 AC 201 ms
4,380 KB
testcase_15 AC 173 ms
4,380 KB
testcase_16 AC 146 ms
4,380 KB
testcase_17 AC 156 ms
4,380 KB
testcase_18 AC 192 ms
4,380 KB
testcase_19 AC 209 ms
4,380 KB
testcase_20 AC 198 ms
4,376 KB
testcase_21 AC 135 ms
4,380 KB
testcase_22 AC 192 ms
4,376 KB
testcase_23 AC 283 ms
4,376 KB
testcase_24 AC 198 ms
4,376 KB
testcase_25 AC 175 ms
4,376 KB
testcase_26 AC 155 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int Kr, Kb;

bool is_valid(string & TS) {
  rep(i, TS.size()) {
    char c = TS[i];

    bool ok = true;
    switch (c) {
      case 'W':
        break;
      case 'R':
        if (i - Kr >= 0 && TS[i - Kr] == 'R')
          ok = false;
        if (i + Kr < TS.size() && TS[i + Kr] == 'R')
          ok = false;
        break;
      case 'B':
        if (i - Kb >= 0 && TS[i - Kb] == 'B')
          ok = false;
        if (i + Kb < TS.size() && TS[i + Kb] == 'B')
          ok = false;
        break;
    }
    if (!ok) return false;
  }

  return true;
}

int solve(string & S, string TS, int idx) {
  if (idx >= S.size())
    return is_valid(TS) ? TS.size() : 0;

  if (S[idx] == 'W') return solve(S, TS + S[idx], idx + 1);
  else return max(solve(S, TS + S[idx], idx + 1), solve(S, TS, idx + 1));
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  string S;
  cin >> Kr >> Kb >> S;
  cout << solve(S, "", 0) << endl;
  return 0;
}
0