結果

問題 No.38 赤青白ブロック
ユーザー furonfuron
提出日時 2023-06-17 18:36:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 542 ms / 5,000 ms
コード長 2,016 bytes
コンパイル時間 1,477 ms
コンパイル使用メモリ 126,500 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 14:47:03
合計ジャッジ時間 17,418 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 521 ms
4,376 KB
testcase_01 AC 473 ms
4,380 KB
testcase_02 AC 497 ms
4,380 KB
testcase_03 AC 504 ms
4,376 KB
testcase_04 AC 495 ms
4,380 KB
testcase_05 AC 518 ms
4,376 KB
testcase_06 AC 506 ms
4,376 KB
testcase_07 AC 494 ms
4,376 KB
testcase_08 AC 540 ms
4,380 KB
testcase_09 AC 513 ms
4,376 KB
testcase_10 AC 538 ms
4,380 KB
testcase_11 AC 525 ms
4,380 KB
testcase_12 AC 521 ms
4,380 KB
testcase_13 AC 532 ms
4,376 KB
testcase_14 AC 513 ms
4,380 KB
testcase_15 AC 508 ms
4,380 KB
testcase_16 AC 490 ms
4,376 KB
testcase_17 AC 494 ms
4,380 KB
testcase_18 AC 505 ms
4,376 KB
testcase_19 AC 479 ms
4,376 KB
testcase_20 AC 507 ms
4,376 KB
testcase_21 AC 473 ms
4,376 KB
testcase_22 AC 486 ms
4,376 KB
testcase_23 AC 542 ms
4,376 KB
testcase_24 AC 498 ms
4,376 KB
testcase_25 AC 524 ms
4,376 KB
testcase_26 AC 491 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <bitset>
#include <set>
#include <stack>
#include <numeric>
#include <unordered_map>
#include <random>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;
const int inf = (1 << 30) - 1;
const ll INF = 1LL << 60;
//const int MOD = 1000000007;
const int MOD = 998244353;

bool check(string& t, int kr, int kb) {
	vi rpos, bpos;
	for (int i = 0; i < t.length(); i++) {
		if (t[i] == 'R') rpos.push_back(i);
		else if (t[i] == 'B') bpos.push_back(i);
	}
	int n = rpos.size();
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int diff = rpos[j] - rpos[i];
			if (diff > kr) break;
			if (diff == kr) return false;
		}
	}
	n = bpos.size();
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int diff = bpos[j] - bpos[i];
			if (diff > kb) break;
			if (diff == kb) return false;
		}
	}
	return true;
}

int main() {
	int kr, kb;
	cin >> kr >> kb;
	string s;
	cin >> s;
	
	int ans = 10;
	const int BMAX = 10;
	bitset<BMAX> bs, bs2;
	int n = 10;
	for (int z = 0; z < (1 << n); z++) {
		bs = z;
		for (int y = 0; y < (1 << n); y++) {
			bs2 = y;
			int r = 0, b = 0;
			string t = "";
			for (int i = 0; i < 30; i++) {
				if (s[i] == 'R') {
					if (bs[r]) t.push_back(s[i]);
					r++;
				}
				else if (s[i] == 'B') {
					if (bs2[b]) t.push_back(s[i]);
					b++;
				}
				else {
					t.push_back(s[i]);
				}
			}
			if (check(t, kr, kb)) {
				ans = max(ans, (int)(10 + bs.count() + bs2.count()));
			}
		}
	}
	cout << ans << endl;

	return 0;
}
0