結果

問題 No.38 赤青白ブロック
ユーザー yuki2006yuki2006
提出日時 2014-10-12 23:47:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,113 ms / 5,000 ms
コード長 1,929 bytes
コンパイル時間 3,655 ms
コンパイル使用メモリ 76,700 KB
実行使用メモリ 61,088 KB
最終ジャッジ日時 2023-08-25 00:55:49
合計ジャッジ時間 32,303 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,025 ms
60,904 KB
testcase_01 AC 998 ms
58,484 KB
testcase_02 AC 978 ms
60,880 KB
testcase_03 AC 1,071 ms
60,656 KB
testcase_04 AC 1,006 ms
61,088 KB
testcase_05 AC 1,080 ms
60,884 KB
testcase_06 AC 893 ms
60,852 KB
testcase_07 AC 886 ms
60,756 KB
testcase_08 AC 995 ms
59,064 KB
testcase_09 AC 910 ms
60,148 KB
testcase_10 AC 1,075 ms
60,624 KB
testcase_11 AC 1,113 ms
60,956 KB
testcase_12 AC 941 ms
60,412 KB
testcase_13 AC 1,102 ms
58,564 KB
testcase_14 AC 980 ms
61,040 KB
testcase_15 AC 1,046 ms
60,656 KB
testcase_16 AC 871 ms
60,664 KB
testcase_17 AC 926 ms
60,852 KB
testcase_18 AC 1,095 ms
60,380 KB
testcase_19 AC 944 ms
60,856 KB
testcase_20 AC 907 ms
60,980 KB
testcase_21 AC 916 ms
60,936 KB
testcase_22 AC 1,010 ms
60,516 KB
testcase_23 AC 1,055 ms
60,624 KB
testcase_24 AC 862 ms
60,688 KB
testcase_25 AC 990 ms
60,840 KB
testcase_26 AC 949 ms
60,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yuki038 {
    public static void main(String[] args) {
        Yuki038 hoge = new Yuki038();
    }

    Yuki038() {
        Scanner scanner = new Scanner(System.in);
        int kr = scanner.nextInt();
        int kb = scanner.nextInt();
        String s = scanner.next();
        int ans = 0;
        int N = s.length();
        int mask = 0;
        for (int i = 0; i < N; i++) {
            if (s.charAt(i) == 'W') {
                mask |= 1 << i;
            }
        }
        for (int i = mask; i < (1 << N); i = (i + 1) | mask) {
            String t = "";
            for (int j = 0; j < N; j++) {
                if (s.charAt(j) == 'W' || (((1 << j) & i) > 0)) {
                    t += (s.charAt(j));
                }
            }
            boolean hit = false;

            LOOP:
            for (int j = 0; j < t.length(); j++) {
                if (t.charAt(j) == 'W') {
                    continue;
                }

                for (int[] c : new int[][]{{'R', kr}, {'B', kb}}) {
                    if (t.charAt(j) == c[0]) {
                        if (j >= c[1]) {
                            if (t.charAt(j - c[1]) == c[0]) {
                                hit = true;
                                break LOOP;
                            }
                        }
                    }
                    if (t.charAt(j) == c[1]) {
                        if (j + c[1] < t.length()) {
                            if (t.charAt(j + c[1]) == c[0]) {
                                hit = true;
                                break LOOP;
                            }
                        }
                    }
                }
            }
            if (!hit) {
                ans = Math.max(ans, t.length());
            }

        }
        System.out.println(ans);

    }

}
0