結果

問題 No.38 赤青白ブロック
ユーザー fantasiabaeticafantasiabaetica
提出日時 2018-10-15 16:06:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 242 ms / 5,000 ms
コード長 1,588 bytes
コンパイル時間 637 ms
コンパイル使用メモリ 66,176 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-02 20:17:58
合計ジャッジ時間 8,173 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 224 ms
4,376 KB
testcase_01 AC 196 ms
4,376 KB
testcase_02 AC 189 ms
4,376 KB
testcase_03 AC 200 ms
4,376 KB
testcase_04 AC 193 ms
4,376 KB
testcase_05 AC 240 ms
4,376 KB
testcase_06 AC 193 ms
4,380 KB
testcase_07 AC 197 ms
4,376 KB
testcase_08 AC 242 ms
4,380 KB
testcase_09 AC 209 ms
4,376 KB
testcase_10 AC 241 ms
4,376 KB
testcase_11 AC 231 ms
4,376 KB
testcase_12 AC 210 ms
4,376 KB
testcase_13 AC 229 ms
4,376 KB
testcase_14 AC 212 ms
4,380 KB
testcase_15 AC 233 ms
4,376 KB
testcase_16 AC 173 ms
4,380 KB
testcase_17 AC 197 ms
4,376 KB
testcase_18 AC 237 ms
4,380 KB
testcase_19 AC 211 ms
4,380 KB
testcase_20 AC 213 ms
4,376 KB
testcase_21 AC 197 ms
4,376 KB
testcase_22 AC 228 ms
4,380 KB
testcase_23 AC 228 ms
4,376 KB
testcase_24 AC 197 ms
4,376 KB
testcase_25 AC 227 ms
4,376 KB
testcase_26 AC 209 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;
#define FOR(i,a,b) for(int i=(a); i<(b); i++)

bool check(string str, int kr, int kb){
    int size = str.size();
    FOR(i, 0, size){
        char str_i = str[i];
        if (str_i == 'R'){
            if (i - kr >= 0){
                if (str[i - kr] == 'R') return false;
            } else if (i + kr < size) {
                if (str[i + kr] == 'R') return false;
            }
        } else if (str_i == 'B') {
            if (i - kb >= 0){
                if (str[i - kb] == 'B') return false;
            } else if (i + kb < size) {
                if (str[i + kb] == 'B') return false;
            }
        }
    }
    return true;
}

int main(){
    int kr, kb;
    string str, str_tmp;
    cin >> kr >> kb;
    cin >> str;

    int ans = 0;
    int max_i = 1 << 20;
    // 一部を抜き出した文字列を生成してループを回す
    FOR(i, 0, max_i){
        // iはループのたびに右にシフトするので別の変数にコピー
        int i_tmp = i;
        str_tmp = "";
        // 文字列の生成
        FOR(j, 0, str.size()){
            char str_j = str[j];
            if (str_j != 'W') {
                if ((i_tmp & 1) == 1){
                    str_tmp += str_j;
                }
                i_tmp = i_tmp >> 1;
            } else {
                str_tmp += str_j;
            }
        }
        if (check(str_tmp, kr, kb)){
            if (str_tmp.size() > ans){
                ans = str_tmp.size();
            }
        }
    }
    cout << ans << endl;

    return 0;
}
0