結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 5 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 12 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 5 ms
4,504 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 WA -
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 6 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 10 ms
4,380 KB
testcase_26 AC 11 ms
4,380 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] == 'R' && i+KR < s.size() && s[i] == s[i+KR]){
            for(int j = i; j <= i+KR; j++) f[j] = true;
        }
        if(s[i] == 'B' && i+KB < s.size() && s[i] == s[i+KB]){
            for(int j = i; j <= i+KB; j++) f[j] = true;
        }
    }
    dfs(0);
    cout << maxv << endl;
}
0