結果

問題 No.38 赤青白ブロック
ユーザー ayame_pyayame_py
提出日時 2016-01-20 13:37:21
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,580 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 162,416 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 13:31:20
合計ジャッジ時間 9,645 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i < (ll)(m); i++)
#define INF 1000000007
#define pb push_back
#define MAX_N 200
#define MAX_T 10010

typedef long long ll;

int Kr,Kb;
string S;

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

bool chk(string s){
    REP(i,s.length()){
        if(s[i]=='R'){
            if(i+Kr<s.length() && s[i+Kr]=='B') return false;
            if(i-Kr>=0 && s[i-Kr]=='B') return false;
        }
        if(s[i]=='B'){
            if(i+Kb<s.length() && s[i+Kb]=='R') return false;
            if(i-Kb>=0 && s[i-Kb]=='R') return false;
        }
    }
    return true;
}

int main(){
    cin >> Kr >> Kb >> S;
    int rcnt=0,bcnt=0;
    int b[10],a[10];
    REP(i,30){
        if(S[i]=='R'){
            a[rcnt]=i;
            rcnt++;
        }
        if(S[i]=='B'){
            b[bcnt]=i;
            bcnt++;
        }
    }
    int ans=0;
    string ans_s="";
    REP(mask,1<<21){
        int use[30];
        REP(i,30){
            if(S[i]=='W') use[i]=1;
            else use[i]=0;
        }
        REP(i,10){
            if(mask<<i & 1) use[a[i]]=1;
        }
        REP(i,10){
            if(mask<<(i+10) & 1) use[b[i]]=1;
        }
        string ts="";
        REP(i,30){
            if(use[i]) ts+=S[i];
        }
        if(chk(ts) && ts.length()>ans){
            ans=ts.length();
            ans_s=ts;
        }
    }
    
    cout << ans_s << endl;
    
    return 0;
}
0