結果
| 問題 |
No.38 赤青白ブロック
|
| コンテスト | |
| ユーザー |
atn112323
|
| 提出日時 | 2016-05-08 13:19:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 208 ms / 5,000 ms |
| コード長 | 807 bytes |
| コンパイル時間 | 506 ms |
| コンパイル使用メモリ | 59,532 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-23 13:01:17 |
| 合計ジャッジ時間 | 6,681 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int Kr, Kb;
string S;
bool check(const string& str) {
for (int i = 0; i < str.length(); i++) {
if (str[i] == 'R' && i + Kr < str.length() && str[i + Kr] == 'R') {
return false;
}
if (str[i] == 'B' && i + Kb < str.length() && str[i + Kb] == 'B') {
return false;
}
}
return true;
}
int main() {
cin >> Kr >> Kb >> S;
int s = 0;
for (int i = 0; i < S.length(); i++) {
if (S[i] != 'W') {
s |= (1 << i);
}
}
int res = 0;
int comb = s;
do {
string str;
for (int i = 0; i < S.length(); i++) {
if (((comb >> i) & 1) == 0) {
str += S[i];
}
}
if (check(str)) {
res = max(res, (int)str.length());
}
comb = (comb - 1) & s;
} while (comb != s);
cout << res << endl;
return 0;
}
atn112323