結果
問題 | No.38 赤青白ブロック |
ユーザー |
|
提出日時 | 2015-02-03 22:10:34 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 37 ms / 5,000 ms |
コード長 | 827 bytes |
コンパイル時間 | 541 ms |
コンパイル使用メモリ | 60,804 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 12:40:56 |
合計ジャッジ時間 | 1,705 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <string> using namespace std; const int N = 30; int kr, kb; string s; int check(int bits) { string str(60, '?'); int nw = 0; int nrb = 0; for (int i = 0; i < N; i++) { if (s[i] == 'W') { str[nw + nrb] = 'W'; nw++; } else if ((bits >> (i - nw)) & 1) { str[nw + nrb] = s[i]; nrb++; } } int len = nw + nrb; for (int i = 0; i < len; i++) { if ((str[i] == 'B' && str[i + kb] == 'B') || (str[i] == 'R' && str[i + kr] == 'R')) { return -1; } } return len; } int main() { cin >> kr >> kb >> s; int limit = 1 << 20; int ans = -1; int n1; for (int i = 0; i < limit; i++) { if (__builtin_popcount(i) + 10 > ans) { ans = max(ans, check(i)); } } cout << ans << endl; return 0; }