結果

問題 No.38 赤青白ブロック
ユーザー GrenacheGrenache
提出日時 2016-03-30 16:54:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 622 ms / 5,000 ms
コード長 1,484 bytes
コンパイル時間 3,270 ms
コンパイル使用メモリ 75,100 KB
実行使用メモリ 60,544 KB
最終ジャッジ日時 2023-08-25 01:15:09
合計ジャッジ時間 20,115 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 622 ms
59,788 KB
testcase_01 AC 579 ms
60,388 KB
testcase_02 AC 550 ms
60,100 KB
testcase_03 AC 578 ms
60,320 KB
testcase_04 AC 572 ms
59,884 KB
testcase_05 AC 514 ms
59,324 KB
testcase_06 AC 541 ms
60,544 KB
testcase_07 AC 555 ms
60,196 KB
testcase_08 AC 550 ms
59,308 KB
testcase_09 AC 529 ms
59,736 KB
testcase_10 AC 506 ms
59,192 KB
testcase_11 AC 530 ms
59,644 KB
testcase_12 AC 562 ms
59,328 KB
testcase_13 AC 521 ms
59,332 KB
testcase_14 AC 524 ms
60,128 KB
testcase_15 AC 587 ms
60,072 KB
testcase_16 AC 538 ms
59,980 KB
testcase_17 AC 523 ms
59,576 KB
testcase_18 AC 603 ms
60,040 KB
testcase_19 AC 567 ms
59,704 KB
testcase_20 AC 603 ms
60,228 KB
testcase_21 AC 539 ms
60,048 KB
testcase_22 AC 543 ms
60,028 KB
testcase_23 AC 586 ms
59,640 KB
testcase_24 AC 584 ms
59,944 KB
testcase_25 AC 566 ms
59,780 KB
testcase_26 AC 529 ms
59,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


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 max = 0;
        for (int mask = 0; mask < 0x1 << 20; mask++) {
            int ir = 0;
            int ib = 0;
        	StringBuilder tmp = new StringBuilder();
            for (int i = 0; i < s.length; i++) {
            	if (s[i] == 'R') {
            		if ((mask & 0x1 << ir++) != 0) {
            			continue;
            		}
            	} else if (s[i] == 'B') {
            		if ((mask & 0x1 << 10 + ib++) != 0) {
            			continue;
            		}
            	}

            	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