結果

問題 No.38 赤青白ブロック
ユーザー yuki2006yuki2006
提出日時 2014-10-12 23:15:17
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,904 bytes
コンパイル時間 3,601 ms
コンパイル使用メモリ 75,828 KB
実行使用メモリ 63,036 KB
最終ジャッジ日時 2023-08-28 20:53:54
合計ジャッジ時間 33,079 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,203 ms
61,260 KB
testcase_01 AC 1,022 ms
61,076 KB
testcase_02 AC 878 ms
61,436 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1,141 ms
61,000 KB
testcase_09 WA -
testcase_10 AC 1,081 ms
60,840 KB
testcase_11 AC 1,139 ms
61,248 KB
testcase_12 AC 910 ms
61,008 KB
testcase_13 AC 1,170 ms
61,172 KB
testcase_14 AC 940 ms
61,220 KB
testcase_15 AC 1,023 ms
61,728 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1,107 ms
61,240 KB
testcase_19 AC 886 ms
60,564 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1,009 ms
60,788 KB
testcase_24 WA -
testcase_25 AC 935 ms
61,048 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

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;

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

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

        }
        System.out.println(ans);

    }

}
0