結果

問題 No.38 赤青白ブロック
ユーザー kurenai3110kurenai3110
提出日時 2016-09-29 22:35:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 1,275 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 84,348 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 01:18:59
合計ジャッジ時間 1,866 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 32 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 11 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;

int Kr,Kb;
string S;
vector<string>SP;
int mx;

int dfs(string word) {
	if (word.size() <= mx)return 0;
	else if (find(SP.begin(), SP.end(), word) != SP.end())return 0;
	else SP.push_back(word);
	set<int> s;
	queue<int> que;


	for (int i = 0; i < word.size(); i++) {
		if (i + Kr < word.size() && word[i] == 'R'&&word[i + Kr] == 'R') {
			for (int j = i; j <= i + Kr; j++) {
				if (word[j] != 'W') s.insert(j);
			}
		}
		else if (i + Kb < word.size() && word[i] == 'B'&&word[i + Kb] == 'B') {
			for (int j = i; j <= i + Kb; j++) {
				if (word[j] != 'W') s.insert(j);
			}
		}
	}
	if (s.size() == 0) return max(mx, (int)word.size());
	for (auto itr = s.begin(); itr != s.end(); itr++) {
		que.push(*itr);
		//cout << *itr << endl;
	}
	//cout << word << endl;
	while (que.size()) {
		//cout << st.size() << endl;
		string word2 = word;
		int p = que.front(); que.pop();
		//cout << p << endl;
		word2.erase(word2.begin() + p);
		mx = max(mx, dfs(word2));
		//cout << word2 << endl;
		//cout << mx << endl;
	}
	return mx;
}


int main()
{
	cin >> Kr >> Kb;
	cin >> S;

	cout << dfs(S) << endl;

	return 0;
}
0