結果
| 問題 | No.38 赤青白ブロック |
| コンテスト | |
| ユーザー |
cormoran
|
| 提出日時 | 2016-09-29 22:13:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 5,000 ms |
| コード長 | 1,272 bytes |
| コンパイル時間 | 1,606 ms |
| コンパイル使用メモリ | 160,132 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-23 13:03:01 |
| 合計ジャッジ時間 | 2,606 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
template<class T> bool set_max(T &a, const T &b) { return a < b ? a = b, true : false; }
class Solver {
public:
int Kr, Kb;
int maxi;
bool check(const string &s) {
auto f = [&](int i, int w, char c) {
int l = i - w, r = i + w;
if(0 <= l and s[l] == c) return false;
if(r < s.size() and s[r] == c) return false;
return true;
};
rep(i, s.size()) {
if(s[i] == 'R' and !f(i, Kr, 'R')) return false;
if(s[i] == 'B' and !f(i, Kb, 'B')) return false;
}
return true;
}
int rec(const string &s, int i) {
if(s.size() <= maxi) return 0;
if(i >= s.size()) return check(s) ? s.size() : 0;
if(s[i] == 'W') return rec(s, i + 1);
int ret = max(rec(s, i + 1), rec(s.substr(0, i) + s.substr(i + 1), i));
set_max(maxi, ret);
return ret;
}
bool solve() {
cin >> Kr >> Kb;
string S; cin >> S;
maxi = 0;
cout << rec(S, 0) << endl;
return 0;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
Solver s;
s.solve();
return 0;
}
cormoran