結果

問題 No.38 赤青白ブロック
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-14 22:30:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 159 ms / 5,000 ms
コード長 900 bytes
コンパイル時間 1,445 ms
コンパイル使用メモリ 147,284 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 01:03:24
合計ジャッジ時間 6,799 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
4,376 KB
testcase_01 AC 144 ms
4,376 KB
testcase_02 AC 152 ms
4,376 KB
testcase_03 AC 145 ms
4,380 KB
testcase_04 AC 147 ms
4,380 KB
testcase_05 AC 158 ms
4,376 KB
testcase_06 AC 153 ms
4,380 KB
testcase_07 AC 154 ms
4,376 KB
testcase_08 AC 154 ms
4,380 KB
testcase_09 AC 153 ms
4,380 KB
testcase_10 AC 145 ms
4,380 KB
testcase_11 AC 150 ms
4,376 KB
testcase_12 AC 149 ms
4,376 KB
testcase_13 AC 154 ms
4,376 KB
testcase_14 AC 148 ms
4,380 KB
testcase_15 AC 159 ms
4,380 KB
testcase_16 AC 145 ms
4,376 KB
testcase_17 AC 147 ms
4,380 KB
testcase_18 AC 153 ms
4,376 KB
testcase_19 AC 143 ms
4,376 KB
testcase_20 AC 157 ms
4,376 KB
testcase_21 AC 145 ms
4,376 KB
testcase_22 AC 159 ms
4,376 KB
testcase_23 AC 150 ms
4,376 KB
testcase_24 AC 153 ms
4,380 KB
testcase_25 AC 157 ms
4,380 KB
testcase_26 AC 144 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int block[30];

int main() {
	int Kr, Kb;
	cin >> Kr >> Kb;
	string S;
	cin >> S;
	vector<int> first;
	int N = S.size();
	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'R') first.push_back(1);
		else if (S[i] == 'B')first.push_back(2);
		else first.push_back(0);
	}
	int nonW = 0;
	for (int i = 0; i < N; i++)
	{
		if (first[i] != 0) nonW++;
	}

	int ans = 0;
	for (int t = 0; t < (1 << nonW); t++)
	{
		int p = 0;
		int q = 0;
		for (int i = 0; i < N; i++)
		{
			if (!first[i]) block[p++] = 0;
			else if ((t >> (q++)) % 2 == 1) block[p++] = first[i];
		}
		bool flag = true;
		for (int i = 0; i < p; i++)
		{
			if (block[i] == 1){
				if (i + Kr < p && block[i + Kr] == 1) flag = false;
			}
			else if (block[i] == 2){
				if (i + Kb < p && block[i + Kb] == 2) flag = false;
			}
		}
		if (flag){
			ans = max(ans, p);
		}
	}
	cout << ans << endl;
}
0