結果

問題 No.38 赤青白ブロック
ユーザー data9824data9824
提出日時 2015-05-20 07:11:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 385 ms / 5,000 ms
コード長 1,126 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 53,704 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 01:06:04
合計ジャッジ時間 11,356 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 372 ms
4,376 KB
testcase_01 AC 347 ms
4,376 KB
testcase_02 AC 334 ms
4,376 KB
testcase_03 AC 360 ms
4,376 KB
testcase_04 AC 349 ms
4,376 KB
testcase_05 AC 369 ms
4,380 KB
testcase_06 AC 329 ms
4,376 KB
testcase_07 AC 323 ms
4,376 KB
testcase_08 AC 362 ms
4,376 KB
testcase_09 AC 336 ms
4,380 KB
testcase_10 AC 378 ms
4,380 KB
testcase_11 AC 380 ms
4,376 KB
testcase_12 AC 354 ms
4,376 KB
testcase_13 AC 385 ms
4,376 KB
testcase_14 AC 349 ms
4,380 KB
testcase_15 AC 360 ms
4,380 KB
testcase_16 AC 315 ms
4,380 KB
testcase_17 AC 339 ms
4,380 KB
testcase_18 AC 369 ms
4,380 KB
testcase_19 AC 357 ms
4,380 KB
testcase_20 AC 339 ms
4,376 KB
testcase_21 AC 324 ms
4,384 KB
testcase_22 AC 331 ms
4,376 KB
testcase_23 AC 375 ms
4,376 KB
testcase_24 AC 335 ms
4,376 KB
testcase_25 AC 354 ms
4,376 KB
testcase_26 AC 355 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int kr, kb;

int length(string& s, int begin, bool remove) {
	int i;
	for (i = begin; i < s.size() && s[i] == 'W'; ++i) {
	}
	if (i == s.size()) {
		string shrunk;
		for (size_t k = 0; k < s.size(); ++k) {
			if (s[k] != '-') {
				shrunk.push_back(s[k]);
			}
		}
		bool invalid = false;
		for (int k = 0; k < shrunk.size() && !invalid; ++k) {
			if (shrunk[k] == 'R') {
				if (k >= kr) {
					invalid |= (shrunk[k - kr] == 'R');
				}
				if (k + kr < shrunk.size()) {
					invalid |= (shrunk[k + kr] == 'R');
				}
			} else if (shrunk[k] == 'B') {
				if (k >= kb) {
					invalid |= (shrunk[k - kb] == 'B');
				}
				if (k + kb < shrunk.size()) {
					invalid |= (shrunk[k + kb] == 'B');
				}
			}
		}
		return invalid ? -1 : shrunk.size();
	}
	char old = s[i];
	if (remove) {
		s[i] = '-';
	}
	int result = max(length(s, i + 1, true), length(s, i + 1, false));
	s[i] = old;
	return result;
}

int main() {
	string s;
	cin >> kr >> kb >> s;
	int result = max(length(s, 0, true), length(s, 0, false));
	cout << result << endl;
	return 0;
}
0