結果

問題 No.38 赤青白ブロック
ユーザー togari_takamototogari_takamoto
提出日時 2016-02-26 15:04:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 222 ms / 5,000 ms
コード長 1,014 bytes
コンパイル時間 1,468 ms
コンパイル使用メモリ 149,668 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 01:13:52
合計ジャッジ時間 8,039 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
4,384 KB
testcase_01 AC 182 ms
4,380 KB
testcase_02 AC 178 ms
4,380 KB
testcase_03 AC 201 ms
4,380 KB
testcase_04 AC 186 ms
4,380 KB
testcase_05 AC 210 ms
4,380 KB
testcase_06 AC 181 ms
4,384 KB
testcase_07 AC 178 ms
4,384 KB
testcase_08 AC 217 ms
4,380 KB
testcase_09 AC 184 ms
4,384 KB
testcase_10 AC 211 ms
4,380 KB
testcase_11 AC 222 ms
4,384 KB
testcase_12 AC 193 ms
4,384 KB
testcase_13 AC 207 ms
4,380 KB
testcase_14 AC 190 ms
4,380 KB
testcase_15 AC 210 ms
4,380 KB
testcase_16 AC 170 ms
4,384 KB
testcase_17 AC 191 ms
4,384 KB
testcase_18 AC 206 ms
4,384 KB
testcase_19 AC 198 ms
4,384 KB
testcase_20 AC 191 ms
4,380 KB
testcase_21 AC 179 ms
4,380 KB
testcase_22 AC 177 ms
4,380 KB
testcase_23 AC 210 ms
4,384 KB
testcase_24 AC 178 ms
4,380 KB
testcase_25 AC 201 ms
4,380 KB
testcase_26 AC 199 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi  = vector<int>; using vb  = vector<bool>; using vd  = vector<double>; using vl  = vector<ll>;
using vvi = vector<vi>;  using vvb = vector<vb>;   using vvd = vector<vd>;     using vvl = vector<vl>;

#define REP(i,n) for(ll i=0; i<(n); ++i)

ll kr, kb;
string s;
vl pos;

ll recur(ll depth, vb & enable){
	if (depth == pos.size()) {
		string ns; REP(i, s.size()) if (enable[i]) ns.push_back(s[i]);
		REP(i, ns.size()) {
			if (ns[i] == 'W') continue;
			ll d = ns[i] == 'R' ? kr : kb;
			if (i - d >= 0 && ns[i - d] == ns[i]) return -1;
			if (i + d < ns.size() && ns[i + d] == ns[i]) return -1;
		}
		return ns.size();
	}

	ll ans = recur(depth + 1, enable);
	enable[pos[depth]] = false;
	ans = max(ans, recur(depth + 1, enable));
	enable[pos[depth]] = true;
	return ans;
}

int main() {
	cin >> kr >> kb >> s;
	REP(i, s.size()) if(s[i]!='W') pos.push_back(i);

	vb enable(s.size(), true);
	cout << recur(0, enable) << endl;

	return 0;
}
0