結果
問題 | No.38 赤青白ブロック |
ユーザー | uafr_cs |
提出日時 | 2015-06-03 17:11:54 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 438 ms / 5,000 ms |
コード長 | 1,515 bytes |
コンパイル時間 | 2,225 ms |
コンパイル使用メモリ | 74,276 KB |
実行使用メモリ | 60,672 KB |
最終ジャッジ日時 | 2023-08-25 01:06:23 |
合計ジャッジ時間 | 13,711 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 438 ms
59,040 KB |
testcase_01 | AC | 345 ms
60,672 KB |
testcase_02 | AC | 343 ms
59,080 KB |
testcase_03 | AC | 344 ms
58,796 KB |
testcase_04 | AC | 342 ms
58,060 KB |
testcase_05 | AC | 397 ms
56,636 KB |
testcase_06 | AC | 349 ms
58,576 KB |
testcase_07 | AC | 370 ms
58,836 KB |
testcase_08 | AC | 425 ms
59,152 KB |
testcase_09 | AC | 380 ms
58,452 KB |
testcase_10 | AC | 367 ms
58,584 KB |
testcase_11 | AC | 367 ms
58,496 KB |
testcase_12 | AC | 347 ms
58,860 KB |
testcase_13 | AC | 400 ms
58,212 KB |
testcase_14 | AC | 328 ms
56,724 KB |
testcase_15 | AC | 389 ms
58,436 KB |
testcase_16 | AC | 335 ms
58,816 KB |
testcase_17 | AC | 366 ms
58,840 KB |
testcase_18 | AC | 428 ms
59,536 KB |
testcase_19 | AC | 344 ms
58,324 KB |
testcase_20 | AC | 373 ms
58,400 KB |
testcase_21 | AC | 357 ms
58,908 KB |
testcase_22 | AC | 383 ms
58,452 KB |
testcase_23 | AC | 374 ms
58,644 KB |
testcase_24 | AC | 354 ms
58,508 KB |
testcase_25 | AC | 339 ms
58,260 KB |
testcase_26 | AC | 343 ms
58,960 KB |
ソースコード
import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); final int Kr = sc.nextInt(); final int Kb = sc.nextInt(); char[] inputs = sc.next().toCharArray(); int min = Integer.MAX_VALUE; for(int bit = 0; bit < (1 << 20); bit++){ final int reduced_size = inputs.length - Integer.bitCount(bit); char[] reduced_inputs = new char[reduced_size]; for(int normal = 0, reduced = 0, count = 0; normal < inputs.length; normal++){ if(inputs[normal] == 'W'){ reduced_inputs[reduced++] = inputs[normal]; continue; } final boolean is_ignored = (bit & (1 << (count++))) != 0; if(is_ignored){ continue; }else{ reduced_inputs[reduced++] = inputs[normal]; } } //System.out.println(Arrays.toString(reduced_inputs)); //sc.next(); boolean ok = true; for(int i = 0; i < reduced_size; i++){ if(reduced_inputs[i] == 'R' && ((i - Kr >= 0 && reduced_inputs[i - Kr] == 'R') || (i + Kr < reduced_size && reduced_inputs[i + Kr] == 'R'))){ ok = false; break; }else if(reduced_inputs[i] == 'B' && ((i - Kb >= 0 && reduced_inputs[i - Kb] == 'B') || (i + Kb < reduced_size && reduced_inputs[i + Kb] == 'B'))){ ok = false; break; } } if(ok){ min = Math.min(min, Integer.bitCount(bit)); } } System.out.println(inputs.length - min); } }