結果
問題 | No.38 赤青白ブロック |
ユーザー | kou6839 |
提出日時 | 2014-12-04 15:13:48 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 414 ms / 5,000 ms |
コード長 | 1,078 bytes |
コンパイル時間 | 3,065 ms |
コンパイル使用メモリ | 73,656 KB |
実行使用メモリ | 45,036 KB |
最終ジャッジ日時 | 2023-08-25 00:57:59 |
合計ジャッジ時間 | 8,647 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 144 ms
40,144 KB |
testcase_01 | AC | 279 ms
44,516 KB |
testcase_02 | AC | 146 ms
40,280 KB |
testcase_03 | AC | 139 ms
39,760 KB |
testcase_04 | AC | 196 ms
40,756 KB |
testcase_05 | AC | 138 ms
39,976 KB |
testcase_06 | AC | 291 ms
44,660 KB |
testcase_07 | AC | 252 ms
43,808 KB |
testcase_08 | AC | 128 ms
39,172 KB |
testcase_09 | AC | 269 ms
43,624 KB |
testcase_10 | AC | 121 ms
39,100 KB |
testcase_11 | AC | 124 ms
39,272 KB |
testcase_12 | AC | 121 ms
39,404 KB |
testcase_13 | AC | 126 ms
39,548 KB |
testcase_14 | AC | 127 ms
39,416 KB |
testcase_15 | AC | 130 ms
39,528 KB |
testcase_16 | AC | 414 ms
45,036 KB |
testcase_17 | AC | 208 ms
42,828 KB |
testcase_18 | AC | 144 ms
40,092 KB |
testcase_19 | AC | 184 ms
40,732 KB |
testcase_20 | AC | 212 ms
42,068 KB |
testcase_21 | AC | 150 ms
40,168 KB |
testcase_22 | AC | 275 ms
43,596 KB |
testcase_23 | AC | 128 ms
39,244 KB |
testcase_24 | AC | 379 ms
45,016 KB |
testcase_25 | AC | 159 ms
40,192 KB |
testcase_26 | AC | 162 ms
40,408 KB |
ソースコード
import java.math.*; import java.util.*; public class Main { static boolean check(int ka,int kb,StringBuffer test){ for(int i=0;i<test.length();i++){ if(test.charAt(i)=='R'){ if(i+ka<test.length() && test.charAt(i+ka)=='R') return false; }else if(test.charAt(i)=='B'){ if(i+kb<test.length() && test.charAt(i+kb)=='B')return false; } } return true; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int ka = sc.nextInt(); int kb = sc.nextInt(); String ss=sc.next(); int[] block = new int[20]; int temp=0; for(int i=29;i>=0;i--){ if(ss.charAt(i)=='R' || ss.charAt(i)=='B' ){ block[temp]=i; temp++; } } int ans=Integer.MAX_VALUE; for(int i=0;i< (1<<21) ;i++){ if(Integer.bitCount(i)>=ans) continue; StringBuffer test = new StringBuffer(ss); for(int j=0;j<20;j++){ if( ( (i>>j) &1) ==1 ){ test.deleteCharAt(block[j]); } } if(check(ka,kb,test)){ ans=Integer.bitCount(i); } } System.out.println(30-ans); } }