結果

問題 No.38 赤青白ブロック
ユーザー NotationNapNotationNap
提出日時 2015-05-04 03:34:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 334 ms / 5,000 ms
コード長 847 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 148,076 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 01:04:35
合計ジャッジ時間 10,916 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 330 ms
4,376 KB
testcase_01 AC 295 ms
4,376 KB
testcase_02 AC 294 ms
4,376 KB
testcase_03 AC 303 ms
4,380 KB
testcase_04 AC 299 ms
4,380 KB
testcase_05 AC 334 ms
4,376 KB
testcase_06 AC 292 ms
4,376 KB
testcase_07 AC 295 ms
4,380 KB
testcase_08 AC 326 ms
4,380 KB
testcase_09 AC 310 ms
4,376 KB
testcase_10 AC 315 ms
4,376 KB
testcase_11 AC 321 ms
4,376 KB
testcase_12 AC 298 ms
4,376 KB
testcase_13 AC 329 ms
4,380 KB
testcase_14 AC 311 ms
4,380 KB
testcase_15 AC 333 ms
4,376 KB
testcase_16 AC 276 ms
4,376 KB
testcase_17 AC 293 ms
4,380 KB
testcase_18 AC 313 ms
4,376 KB
testcase_19 AC 298 ms
4,376 KB
testcase_20 AC 308 ms
4,380 KB
testcase_21 AC 286 ms
4,376 KB
testcase_22 AC 325 ms
4,380 KB
testcase_23 AC 318 ms
4,376 KB
testcase_24 AC 292 ms
4,376 KB
testcase_25 AC 314 ms
4,376 KB
testcase_26 AC 310 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

bool ok(string t, int Kr, int Kb) {
	REP(i, t.size()) {
		if (t[i] == 'R') {
			int j = i + Kr;
			if (j < t.size() && t[j] == 'R') return false;
		}
		if (t[i] == 'B') {
			int j = i + Kb;
			if (j < t.size() && t[j] == 'B') return false;
		}
	}
	return true;
}
int main() {
	int Kr, Kb; cin >> Kr >> Kb;
	string s; cin >> s;

	vector<int> pos;
	REP(i, s.size()) if (s[i] == 'R' || s[i] == 'B') {
		pos.push_back(i);
	}

	int ans = 0;
	int n = pos.size();
	REP(st, 1 << n) {
		int rem = 0;
		REP(i, n) if (st >> i & 1) {
			rem |= 1 << pos[i];
		}
		string t;
		REP(i, s.size()) {
			if ((rem >> i & 1) == 0) t += s[i];
		}
		if (ok(t, Kr, Kb)) {
			int cur = t.size();
			ans = max(ans, cur);
		}
	}
	cout << ans << endl;
}
0