結果

問題 No.38 赤青白ブロック
ユーザー 37zigen37zigen
提出日時 2016-05-01 22:29:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 567 ms / 5,000 ms
コード長 1,066 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 74,820 KB
実行使用メモリ 60,680 KB
最終ジャッジ日時 2023-08-25 01:15:27
合計ジャッジ時間 10,999 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 238 ms
59,172 KB
testcase_01 AC 393 ms
60,064 KB
testcase_02 AC 244 ms
60,276 KB
testcase_03 AC 239 ms
59,296 KB
testcase_04 AC 224 ms
59,396 KB
testcase_05 AC 223 ms
58,976 KB
testcase_06 AC 567 ms
59,432 KB
testcase_07 AC 250 ms
59,992 KB
testcase_08 AC 225 ms
59,068 KB
testcase_09 AC 351 ms
59,876 KB
testcase_10 AC 224 ms
58,628 KB
testcase_11 AC 223 ms
59,100 KB
testcase_12 AC 221 ms
58,856 KB
testcase_13 AC 221 ms
59,336 KB
testcase_14 AC 222 ms
60,680 KB
testcase_15 AC 248 ms
59,160 KB
testcase_16 AC 267 ms
59,048 KB
testcase_17 AC 314 ms
59,296 KB
testcase_18 AC 304 ms
60,356 KB
testcase_19 AC 240 ms
59,868 KB
testcase_20 AC 238 ms
59,796 KB
testcase_21 AC 245 ms
59,468 KB
testcase_22 AC 438 ms
58,820 KB
testcase_23 AC 220 ms
58,884 KB
testcase_24 AC 306 ms
59,460 KB
testcase_25 AC 232 ms
59,112 KB
testcase_26 AC 239 ms
59,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.Scanner;
public class Main{
	public static void main(String[] args)throws Exception{
		new Main().solve();
	}
	boolean check(int kr,int kb,StringBuffer sb){
		for(int i=0;i<sb.length();i++){
			if(sb.charAt(i)=='R'&&i+kr<sb.length()&&sb.charAt(i+kr)=='R'){
				return false;
			}else if(sb.charAt(i)=='B'&&i+kb<sb.length()&&sb.charAt(i+kb)=='B'){
				return false;
			}
		}
		return true;
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		int kr=sc.nextInt();
		int kb=sc.nextInt();
		String s=sc.next();
		
		int[] block=new int[20];
		int tmp=0;
		for(int i=0;i<30;i++){
			if(s.charAt(i)=='R'||s.charAt(i)=='B'){
				block[tmp]=i;
				tmp++;
			}
		}
		int ans=9999999;
		for(int i=0;i<(1<<21);i++){
			StringBuffer sb=new StringBuffer(s);
			if(ans<=Integer.bitCount(i))continue;
			for(int j=19;j>=0;j--){
				if((1&(i>>j))==1){
					sb=sb.deleteCharAt(block[j]);
				}
			}
//			System.out.println(sb);
			if(check(kr, kb, sb)){
				ans=Math.min(ans,Integer.bitCount(i));
			}
		}
		System.out.println(30-ans);
	}

}
0