結果

問題 No.38 赤青白ブロック
ユーザー krotonkroton
提出日時 2014-10-12 23:36:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 282 ms / 5,000 ms
コード長 1,637 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 71,640 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 00:51:40
合計ジャッジ時間 8,685 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 265 ms
4,380 KB
testcase_01 AC 237 ms
4,376 KB
testcase_02 AC 236 ms
4,380 KB
testcase_03 AC 255 ms
4,376 KB
testcase_04 AC 246 ms
4,380 KB
testcase_05 AC 271 ms
4,376 KB
testcase_06 AC 238 ms
4,376 KB
testcase_07 AC 234 ms
4,376 KB
testcase_08 AC 278 ms
4,380 KB
testcase_09 AC 252 ms
4,380 KB
testcase_10 AC 280 ms
4,380 KB
testcase_11 AC 278 ms
4,380 KB
testcase_12 AC 256 ms
4,380 KB
testcase_13 AC 282 ms
4,376 KB
testcase_14 AC 251 ms
4,380 KB
testcase_15 AC 256 ms
4,376 KB
testcase_16 AC 232 ms
4,380 KB
testcase_17 AC 236 ms
4,376 KB
testcase_18 AC 259 ms
4,380 KB
testcase_19 AC 240 ms
4,376 KB
testcase_20 AC 254 ms
4,384 KB
testcase_21 AC 226 ms
4,380 KB
testcase_22 AC 233 ms
4,376 KB
testcase_23 AC 279 ms
4,376 KB
testcase_24 AC 239 ms
4,380 KB
testcase_25 AC 262 ms
4,380 KB
testcase_26 AC 242 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <fstream>
#include <sstream>
using namespace std;
typedef long long ll;

int Kr, Kb;

bool check(string s){
    for(int i=0;i<s.size();i++){
        if(s[i] == 'W')continue;
        
        if(s[i] == 'R'){
            if(i - Kr >= 0)if(s[i - Kr] == 'R')return false;
            if(i + Kr < s.size())if(s[i + Kr] == 'R')return false;
        } else {
            if(i - Kb >= 0)if(s[i - Kb] == 'B')return false;
            if(i + Kb < s.size())if(s[i + Kb] == 'B')return false;
        }
    }
    
    return true;
}

int main(){
    cin >> Kr >> Kb;
    
    string S;
    cin >> S;
    
    int res = 0;
    for(int r=0;r<1<<10;r++)for(int b=0;b<1<<10;b++){
        int rc = 0;
        int bc = 0;
        
        string s = "";
        for(int i=0;i<S.size();i++){
            if(S[i] == 'W'){
                s += 'W';
                continue;
            }
            
            if(S[i] == 'R'){
                if((r >> rc) & 1){
                    
                } else {
                    s += 'R';
                }
                
                ++rc;
            } else {
                if((b >> bc) & 1){
                    
                } else {
                    s += 'B';
                }
                
                ++bc;
            }
        }
        
        if(check(s)){
            res = max(res, (int)s.size());
        }
    }
    
    cout << res << endl;
    return 0;
}
0