結果
| 問題 |
No.38 赤青白ブロック
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-10-15 12:13:34 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 5,000 ms |
| コード長 | 1,091 bytes |
| コンパイル時間 | 3,245 ms |
| コンパイル使用メモリ | 140,200 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-17 16:48:51 |
| 合計ジャッジ時間 | 4,600 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
int Kr, Kb;
string S;
int N;
int dfs(int i, int idx, vector<char> &str) {
if (i >= N) {
return idx;
}
int res = 0;
if (S[i] == 'W') {
str[idx] = 'W';
res = max(res, dfs(i + 1, idx + 1, str));
str[idx] = '#';
} else if (S[i] == 'R') {
if (idx - Kr < 0 || (idx - Kr >= 0 && str[idx - Kr] != 'R')) {
str[idx] = 'R';
res = max(res, dfs(i + 1, idx + 1, str));
str[idx] = '#';
}
res = max(res, dfs(i + 1, idx, str));
} else {
if (idx - Kb < 0 || (idx - Kb >= 0 && str[idx - Kb] != 'B')) {
str[idx] = 'B';
res = max(res, dfs(i + 1, idx + 1, str));
str[idx] = '#';
}
res = max(res, dfs(i + 1, idx, str));
}
return res;
}
int main() {
cin >> Kr >> Kb;
cin >> S;
N = S.size();
vector<char> str(N);
cout << dfs(0, 0, str) << endl;
return 0;
}
siman