結果
| 問題 |
No.38 赤青白ブロック
|
| コンテスト | |
| ユーザー |
ninoinui
|
| 提出日時 | 2020-07-29 16:54:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 279 ms / 5,000 ms |
| コード長 | 834 bytes |
| コンパイル時間 | 2,208 ms |
| コンパイル使用メモリ | 193,436 KB |
| 最終ジャッジ日時 | 2025-01-12 07:37:27 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int R, B;
bool f(string s) {
int n = s.size();
for (int i = 0; i < n; i++) {
if (s.at(i) == 'R') {
if (i - R >= 0) if (s.at(i - R) == 'R') return false;
if (i + R < n) if (s.at(i + R) == 'R') return false;
}
if (s.at(i) == 'B') {
if (i - B >= 0) if (s.at(i - B) == 'B') return false;
if (i + B < n) if (s.at(i + B) == 'B') return false;
}
}
return true;
}
int main() {
string S;
cin >> R >> B >> S;
int ans = 0;
for (int bit = 0; bit < 1 << 20; bit++) {
string tmp;
int cnt = 0;
for (auto c : S) {
if (c == 'W') {
tmp += 'W';
continue;
}
if (bit >> cnt & 1) {
tmp += c;
}
cnt++;
}
if (f(tmp)) ans = max(ans, (int) tmp.size());
}
cout << ans << "\n";
}
ninoinui