結果

問題 No.38 赤青白ブロック
ユーザー goodbatongoodbaton
提出日時 2015-08-06 20:51:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 600 ms / 5,000 ms
コード長 1,246 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 80,268 KB
実行使用メモリ 22,220 KB
最終ジャッジ日時 2023-08-25 01:08:29
合計ジャッジ時間 2,642 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>

typedef long long ll;
using namespace std;

#define mod 1000000009
#define INF 1000000000
#define LLINF 2000000000000000000LL
#define PI 3.1415926536

#define SIZE 101

int kr,kb,ans;
string S;
set<string> memo;

int dfs(string s){
    bool f =true;
    string ch;
    int ret = 0;
    
    if(s.size() <= ans) return 0;
    if(memo.find(s)!=memo.end()) return 0;
    memo.insert(s);
    
    for(int i=0;i<=s.size();i++){
        if(s[i]=='R'){
            if(0<=i-kr && s[i-kr]=='R') f = false;
            if(i+kr<s.size() && s[i+kr]=='R') f = false;
        }
        if(s[i]=='B'){
            if(0<=i-kb && s[i-kb]=='B') f = false;
            if(i+kb<s.size() && s[i+kb]=='B') f = false;
        }
    }
    
    if(f){
        ans = s.size();
        return (int)s.size();
    }
    
    for(int i=0;i<s.size();i++){
        ch = s;
        ch.erase(ch.begin()+i);
        ret = max(dfs(ch),ret);
    }
    
    return ret;
}

int main(){
    
    cin >> kr >> kb >> S;
    
    cout << dfs(S) << endl;
    
    return 0;
}
0