結果

問題 No.38 赤青白ブロック
ユーザー myantamyanta
提出日時 2017-05-04 19:42:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 845 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 40,804 KB
実行使用メモリ 4,484 KB
最終ジャッジ日時 2023-10-12 08:07:19
合計ジャッジ時間 2,282 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<vector>


using namespace std;


using s_t=vector<int>;

int kr, kb;


int max_u(int& m, int v)
{
	if(m<v)
	{
		m=v;
		return 1;
	}
	return 0;
}


int solve(s_t& s)
{
	int i, f, is_ok=1, ret=0;
	s_t w;

	for(i=0;i<s.size();i++)
	{
		if(i>0 && s[i]==s[i-1]) continue;

		f=0;
		if(s[i]=='R')
		{
			if(i+kr<s.size() && s[i+kr]=='R') f=1;
			if(i-kr>=0 && s[i-kr]=='R') f=1;
		}
		if(s[i]=='B')
		{
			if(i+kb<s.size() && s[i+kb]=='B') f=1;
			if(i-kb>=0 && s[i-kb]=='B') f=1;
		}

		if(f)
		{
			is_ok=0;
			w=s;
			w.erase(w.begin()+i);
			max_u(ret, solve(w));
		}
	}
	if(is_ok) max_u(ret, s.size());
	return ret;
}


int main(void)
{
	char cs[30+2];
	s_t s;

	while(scanf("%d%d%s", &kr, &kb, cs)==3)
	{
		s.clear();
		for(int i=0;cs[i];i++)
		{
			s.push_back(cs[i]);
		}
		printf("%d\n", solve(s));
	}

	return 0;
}
0