結果

問題 No.38 赤青白ブロック
ユーザー GrenacheGrenache
提出日時 2016-03-30 00:05:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,360 ms / 5,000 ms
コード長 1,794 bytes
コンパイル時間 3,471 ms
コンパイル使用メモリ 77,260 KB
実行使用メモリ 65,120 KB
最終ジャッジ日時 2023-08-25 01:16:54
合計ジャッジ時間 37,805 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,187 ms
62,388 KB
testcase_01 AC 1,201 ms
62,228 KB
testcase_02 AC 1,108 ms
62,312 KB
testcase_03 AC 1,101 ms
61,944 KB
testcase_04 AC 1,127 ms
62,216 KB
testcase_05 AC 1,080 ms
61,916 KB
testcase_06 AC 1,360 ms
65,120 KB
testcase_07 AC 1,175 ms
61,944 KB
testcase_08 AC 1,172 ms
62,632 KB
testcase_09 AC 1,189 ms
62,788 KB
testcase_10 AC 1,158 ms
62,328 KB
testcase_11 AC 1,130 ms
63,288 KB
testcase_12 AC 1,110 ms
62,028 KB
testcase_13 AC 1,142 ms
62,084 KB
testcase_14 AC 1,187 ms
61,812 KB
testcase_15 AC 1,226 ms
62,920 KB
testcase_16 AC 1,155 ms
63,036 KB
testcase_17 AC 1,138 ms
62,040 KB
testcase_18 AC 1,184 ms
62,836 KB
testcase_19 AC 1,152 ms
62,072 KB
testcase_20 AC 1,162 ms
63,116 KB
testcase_21 AC 1,138 ms
61,888 KB
testcase_22 AC 1,195 ms
62,792 KB
testcase_23 AC 1,179 ms
62,804 KB
testcase_24 AC 1,279 ms
62,652 KB
testcase_25 AC 1,190 ms
61,216 KB
testcase_26 AC 1,092 ms
62,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


public class Main_yukicoder38 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int kr = sc.nextInt();
        int kb = sc.nextInt();
        char[] s = sc.next().toCharArray();

        int[] r = new int[10];
        int[] b = new int[10];
        int ir = 0;
        int ib = 0;
        for (int i = 0; i < s.length; i++) {
        	if (s[i] == 'R') {
        		r[ir++] = i;
        	} else if (s[i] == 'B') {
        		b[ib++] = i;
        	}
        }

        int max = 0;
        for (int mask = 0; mask < 0x1 << 20; mask++) {
        	Set<Integer> hs = new HashSet<>();
        	for (int i = 0; i < 20; i++) {
        		if ((mask & 0x1 << i) != 0) {
        			if (i < 10) {
        				hs.add(r[i]);
        			} else {
        				hs.add(b[i - 10]);
        			}
        		}
        	}

        	StringBuilder tmp = new StringBuilder();
        	for (int i = 0; i < s.length; i++) {
        		if (!hs.contains(i)) {
        			tmp.append(s[i]);
        		}
        	}

        	if (isOK(tmp, kr, kb)) {
        		max = Math.max(max, 30 - Integer.bitCount(mask));
        	}
        }

        System.out.println(max);

        sc.close();
    }

	private static boolean isOK(StringBuilder s, int kr, int kb) {
		int n = s.length();
		for (int i = 0; i < n; i++) {
			if (s.charAt(i) == 'R') {
				if (i - kr >= 0 && s.charAt(i - kr) == 'R') {
					return false;
				}
				if (i + kr < n && s.charAt(i + kr) == 'R') {
					return false;
				}
			} else if (s.charAt(i) == 'B') {
				if (i - kb >= 0 && s.charAt(i - kb) == 'B') {
					return false;
				}
				if (i + kb < n && s.charAt(i + kb) == 'B') {
					return false;
				}
			}
		}

		return true;
	}
}
0