結果

問題 No.38 赤青白ブロック
ユーザー masamasa
提出日時 2015-02-03 21:58:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 218 ms / 5,000 ms
コード長 771 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 61,632 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-25 00:58:27
合計ジャッジ時間 7,144 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 213 ms
4,380 KB
testcase_01 AC 189 ms
4,380 KB
testcase_02 AC 190 ms
4,376 KB
testcase_03 AC 191 ms
4,384 KB
testcase_04 AC 193 ms
4,504 KB
testcase_05 AC 218 ms
4,376 KB
testcase_06 AC 192 ms
4,376 KB
testcase_07 AC 188 ms
4,380 KB
testcase_08 AC 217 ms
4,380 KB
testcase_09 AC 213 ms
4,380 KB
testcase_10 AC 210 ms
4,376 KB
testcase_11 AC 209 ms
4,376 KB
testcase_12 AC 193 ms
4,376 KB
testcase_13 AC 214 ms
4,380 KB
testcase_14 AC 207 ms
4,380 KB
testcase_15 AC 217 ms
4,380 KB
testcase_16 AC 177 ms
4,504 KB
testcase_17 AC 190 ms
4,384 KB
testcase_18 AC 212 ms
4,380 KB
testcase_19 AC 195 ms
4,376 KB
testcase_20 AC 199 ms
4,380 KB
testcase_21 AC 182 ms
4,380 KB
testcase_22 AC 213 ms
4,380 KB
testcase_23 AC 206 ms
4,380 KB
testcase_24 AC 185 ms
4,380 KB
testcase_25 AC 207 ms
4,376 KB
testcase_26 AC 199 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

const int N = 30;
int kr, kb;
string s;

int check(int bits) {
	string str(60, '?');
	int nw = 0;
	int nrb = 0;

	for (int i = 0; i < N; i++) {
		if (s[i] == 'W') {
			str[nw + nrb] = 'W';
			nw++;
		} else if ((bits >> (i - nw)) & 1) {
			str[nw + nrb] = s[i];
			nrb++;
		}
	}

	int len = nw + nrb;
	for (int i = 0; i < len; i++) {
		if ((str[i] == 'B' && str[i + kb] == 'B') || (str[i] == 'R' && str[i + kr] == 'R')) {
			return -1;
		}
	}
	return len;
}

int main() {

	cin >> kr >> kb >> s;
	int limit = 1 << 20;
	int ans = -1;
	for (int i = 0; i < limit; i++) {
		ans = max(ans, check(i));
	}
	cout << ans << endl;
	return 0;
}
0