結果

問題 No.38 赤青白ブロック
ユーザー hotpepsihotpepsi
提出日時 2015-06-16 00:45:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 113 ms / 5,000 ms
コード長 921 bytes
コンパイル時間 443 ms
コンパイル使用メモリ 65,368 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 01:07:01
合計ジャッジ時間 4,227 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
4,376 KB
testcase_01 AC 85 ms
4,376 KB
testcase_02 AC 100 ms
4,380 KB
testcase_03 AC 99 ms
4,376 KB
testcase_04 AC 72 ms
4,376 KB
testcase_05 AC 112 ms
4,376 KB
testcase_06 AC 70 ms
4,384 KB
testcase_07 AC 75 ms
4,384 KB
testcase_08 AC 113 ms
4,376 KB
testcase_09 AC 79 ms
4,376 KB
testcase_10 AC 111 ms
4,376 KB
testcase_11 AC 110 ms
4,380 KB
testcase_12 AC 107 ms
4,376 KB
testcase_13 AC 113 ms
4,380 KB
testcase_14 AC 93 ms
4,376 KB
testcase_15 AC 109 ms
4,380 KB
testcase_16 AC 49 ms
4,376 KB
testcase_17 AC 98 ms
4,376 KB
testcase_18 AC 107 ms
4,380 KB
testcase_19 AC 104 ms
4,376 KB
testcase_20 AC 86 ms
4,376 KB
testcase_21 AC 95 ms
4,380 KB
testcase_22 AC 93 ms
4,384 KB
testcase_23 AC 108 ms
4,376 KB
testcase_24 AC 71 ms
4,380 KB
testcase_25 AC 105 ms
4,376 KB
testcase_26 AC 106 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
	string s;
	getline(cin, s);
	stringstream ss(s);
	int Kr, Kb;
	ss >> Kr >> Kb;
	getline(cin, s);

	int rb = 0;
	int cnt[256] = {};
	for (char c : s) {
		cnt[c] += 1;
	}
	int m = 1 << (cnt['R'] + cnt['B']);
	int ans = 0;
	for (int b = 0; b < m; ++b) {
		char w[32];
		int bpos = 0, wpos = 0;
		bool f = true;
		for (char c : s) {
			if (c == 'W') {
				w[wpos++] = c;
			} else {
				if ((1 << bpos) & b) {
					if (c == 'R') {
						if (wpos >= Kr && w[wpos - Kr] == 'R') {
							f = false;
							break;
						}
					} else {
						if (wpos >= Kb && w[wpos - Kb] == 'B') {
							f = false;
							break;
						}
					}
					w[wpos++] = c;
				}
				++bpos;
			}
		}
		if (f) {
			ans = max(ans, wpos);
		}
	}
	cout << ans << endl;
	return 0;
}
0