結果

問題 No.38 赤青白ブロック
ユーザー konsin_tokage
提出日時 2018-04-13 07:27:17
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 515 bytes
コンパイル時間 483 ms
コンパイル使用メモリ 55,720 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-26 21:37:18
合計ジャッジ時間 1,659 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
int kr, kb;
char s[31];
int rec(int i, int r, int b){
    if(i == 30) return __builtin_popcount(r) + __builtin_popcount(b);
    if(s[i] == 'W') return rec(i+1, r<<1, b<<1);
    int res = rec(i+1, r, b);
    if(s[i]=='R' && !(r&1<<(kr-1))) res = max(res, rec(i+1, r<<1|1, b<<1));
    if(s[i]=='B' && !(b&1<<(kb-1))) res = max(res, rec(i+1, r<<1, b<<1|1));
    return res;
}
int main(){
    cin >> kr >> kb;
    cin >> s;
    cout << 10 + rec(0, 0, 0) << endl;
    return 0;
}
0