結果

問題 No.38 赤青白ブロック
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-04-16 17:01:18
言語 Java
(openjdk 23)
結果
AC  
実行時間 438 ms / 5,000 ms
コード長 1,714 bytes
コンパイル時間 3,445 ms
コンパイル使用メモリ 78,744 KB
実行使用メモリ 60,016 KB
最終ジャッジ日時 2024-12-23 12:46:25
合計ジャッジ時間 9,566 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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