結果

問題 No.38 赤青白ブロック
ユーザー なおなお
提出日時 2014-10-13 00:54:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 790 bytes
コンパイル時間 1,829 ms
コンパイル使用メモリ 52,496 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-28 21:01:56
合計ジャッジ時間 2,078 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 4 ms
4,384 KB
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

int KR,KB,maxv;
string s,k;
bool f[32];

void dfs(int i){
    if(i == s.size()){
        maxv = max(maxv, (int)k.size());
        return;
    }
    if(s[i] != 'W' && f[i]) dfs(i+1);
    int ks = k.size();
    if(
        (s[i] == 'R' && ( ks-KR < 0 || k[ks-KR] != 'R' )) ||
        (s[i] == 'B' && ( ks-KB < 0 || k[ks-KB] != 'B' )) || 
        (s[i] == 'W'))
    {
        k.push_back(s[i]);
        dfs(i+1);
        k.pop_back();
    }
}

int main(){
    cin >> KR >> KB >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != 'W' && i+KR < s.size() && s[i] == s[i+KR]){
            for(int j = i+1; j < i+KR; j++) f[j] = true;
        }
    }
    dfs(0);
    cout << maxv << endl;
}
0