結果

問題 No.38 赤青白ブロック
コンテスト
ユーザー konsin_tokage
提出日時 2018-04-12 23:22:16
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 616 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 481 ms
コンパイル使用メモリ 71,788 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-13 18:01:25
合計ジャッジ時間 1,959 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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