結果

問題 No.38 赤青白ブロック
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-04-16 17:01:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 350 ms / 5,000 ms
コード長 1,714 bytes
コンパイル時間 3,500 ms
コンパイル使用メモリ 75,876 KB
実行使用メモリ 60,596 KB
最終ジャッジ日時 2023-08-25 01:04:13
合計ジャッジ時間 9,985 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
56,924 KB
testcase_01 AC 350 ms
60,596 KB
testcase_02 AC 172 ms
57,120 KB
testcase_03 AC 174 ms
57,044 KB
testcase_04 AC 168 ms
56,852 KB
testcase_05 AC 163 ms
57,420 KB
testcase_06 AC 185 ms
59,784 KB
testcase_07 AC 174 ms
56,644 KB
testcase_08 AC 169 ms
57,088 KB
testcase_09 AC 203 ms
59,444 KB
testcase_10 AC 159 ms
57,088 KB
testcase_11 AC 166 ms
56,736 KB
testcase_12 AC 168 ms
57,428 KB
testcase_13 AC 167 ms
57,324 KB
testcase_14 AC 165 ms
56,420 KB
testcase_15 AC 167 ms
56,804 KB
testcase_16 AC 268 ms
58,564 KB
testcase_17 AC 175 ms
59,496 KB
testcase_18 AC 169 ms
59,656 KB
testcase_19 AC 185 ms
59,060 KB
testcase_20 AC 189 ms
59,584 KB
testcase_21 AC 173 ms
56,936 KB
testcase_22 AC 336 ms
60,452 KB
testcase_23 AC 167 ms
57,044 KB
testcase_24 AC 214 ms
59,684 KB
testcase_25 AC 173 ms
56,976 KB
testcase_26 AC 184 ms
59,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//No.38 赤青白ブロック

import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class No38 {
    
    static final Scanner in = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);

    static void solve() {
        int kr = in.nextInt();
        int kb = in.nextInt();
        char[] cs = in.next().toCharArray();
        int max = 0;

        for (int i=0; i<1<<20; i++) {
            if (Integer.bitCount(i)+10 < max) continue;
            StringBuilder sb = new StringBuilder();
            for (int j=0, ptr = 0; j<30; j++) {
                if (cs[j] == 'W') {
                    sb.append('W');
                    continue;
                }
                if ((i>>ptr&1) == 1) sb.append(cs[j]);
                ptr++;
            }
            if (isOk(sb.toString().toCharArray(),kr,kb)) {
                max = max(max,sb.length());
            }
        }

        out.println(max);
    }

    static boolean isOk(char[] cs, int kr, int kb) {
        int n = cs.length;
        for (int i=0; i<n; i++) {
            if (cs[i] == 'R') {
                if (i + kr < n && cs[i+kr] == 'R') return false;
            }else if (cs[i] == 'B') {
                if (i + kb < n && cs[i+kb] == 'B') return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        solve();
        out.flush();

        long end = System.currentTimeMillis();
        //trace(end-start + "ms");
        in.close();
        out.close();
    }

    static void trace(Object... o) { System.out.println(deepToString(o));}
}
0