結果

問題 No.38 赤青白ブロック
ユーザー ぴろずぴろず
提出日時 2015-02-15 14:59:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 602 ms / 5,000 ms
コード長 1,169 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 74,072 KB
実行使用メモリ 61,864 KB
最終ジャッジ日時 2023-08-25 01:00:05
合計ジャッジ時間 17,720 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 531 ms
61,016 KB
testcase_01 AC 594 ms
61,348 KB
testcase_02 AC 536 ms
60,892 KB
testcase_03 AC 602 ms
61,864 KB
testcase_04 AC 531 ms
60,872 KB
testcase_05 AC 508 ms
60,824 KB
testcase_06 AC 514 ms
61,052 KB
testcase_07 AC 518 ms
61,220 KB
testcase_08 AC 480 ms
60,212 KB
testcase_09 AC 541 ms
60,812 KB
testcase_10 AC 500 ms
60,832 KB
testcase_11 AC 484 ms
60,832 KB
testcase_12 AC 526 ms
60,816 KB
testcase_13 AC 471 ms
60,836 KB
testcase_14 AC 529 ms
61,072 KB
testcase_15 AC 515 ms
60,704 KB
testcase_16 AC 551 ms
61,340 KB
testcase_17 AC 511 ms
60,724 KB
testcase_18 AC 514 ms
60,624 KB
testcase_19 AC 510 ms
60,376 KB
testcase_20 AC 546 ms
60,916 KB
testcase_21 AC 508 ms
61,048 KB
testcase_22 AC 528 ms
60,896 KB
testcase_23 AC 523 ms
60,752 KB
testcase_24 AC 530 ms
61,044 KB
testcase_25 AC 529 ms
61,140 KB
testcase_26 AC 516 ms
60,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no038;

import java.util.Scanner;

public class Main {

	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 n = 30;
		int nr = 10, nb = 10;
		int ans = 0;
		for(int i=0;i<1<<nr;i++) {
			for(int j=0;j<1<<nb;j++) {
				StringBuilder sb = new StringBuilder();
				int r = 0, b = 0;
				for(int k=0;k<n;k++) {
					if (s[k] == 'R') {
						if ((i>>r&1) == 0) {
							sb.append(s[k]);
						}
						r++;
					}else if (s[k] == 'B') {
						if ((j>>b&1) == 0) {
							sb.append(s[k]);
						}
						b++;
					}else if(s[k] == 'W') {
						sb.append(s[k]);
					}
				}
				String t = sb.toString();
				if (isValidString(t, kr, kb)) {
					ans = Math.max(ans,t.length());
				}
			}
		}
		System.out.println(ans);
	}

	public static boolean isValidString(String t,int kr,int kb) {
		char[] s = t.toCharArray();
		int n = s.length;
		for(int i=0;i<n-kr;i++) {
			if (s[i] == 'R' && s[i+kr] == 'R') {
				return false;
			}
		}
		for(int i=0;i<n-kb;i++) {
			if (s[i] == 'B' && s[i+kb] == 'B') {
				return false;
			}
		}
		return true;
	}
}
0