結果
問題 | No.38 赤青白ブロック |
ユーザー | scache |
提出日時 | 2014-10-13 00:12:26 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 748 ms / 5,000 ms |
コード長 | 1,283 bytes |
コンパイル時間 | 4,644 ms |
コンパイル使用メモリ | 74,320 KB |
実行使用メモリ | 71,800 KB |
最終ジャッジ日時 | 2023-08-25 00:53:19 |
合計ジャッジ時間 | 13,905 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 240 ms
64,356 KB |
testcase_01 | AC | 438 ms
67,284 KB |
testcase_02 | AC | 318 ms
63,836 KB |
testcase_03 | AC | 340 ms
65,128 KB |
testcase_04 | AC | 589 ms
62,996 KB |
testcase_05 | AC | 124 ms
56,068 KB |
testcase_06 | AC | 401 ms
66,056 KB |
testcase_07 | AC | 436 ms
66,840 KB |
testcase_08 | AC | 127 ms
55,860 KB |
testcase_09 | AC | 494 ms
65,752 KB |
testcase_10 | AC | 121 ms
56,184 KB |
testcase_11 | AC | 122 ms
56,252 KB |
testcase_12 | AC | 121 ms
56,036 KB |
testcase_13 | AC | 119 ms
55,976 KB |
testcase_14 | AC | 118 ms
56,128 KB |
testcase_15 | AC | 261 ms
64,252 KB |
testcase_16 | AC | 394 ms
64,772 KB |
testcase_17 | AC | 567 ms
68,516 KB |
testcase_18 | AC | 206 ms
60,724 KB |
testcase_19 | AC | 377 ms
67,692 KB |
testcase_20 | AC | 708 ms
70,736 KB |
testcase_21 | AC | 376 ms
66,124 KB |
testcase_22 | AC | 748 ms
71,800 KB |
testcase_23 | AC | 160 ms
56,124 KB |
testcase_24 | AC | 503 ms
70,172 KB |
testcase_25 | AC | 261 ms
63,568 KB |
testcase_26 | AC | 301 ms
64,288 KB |
ソースコード
import java.util.Scanner; public class Main2 { public static void main(String[] args) { Main2 p = new Main2(); } public Main2() { Scanner sc = new Scanner(System.in); int kr = sc.nextInt(); int kb = sc.nextInt(); String s = sc.next(); solve(kr, kb, s); } public void solve(int kr, int kb, String s) { int res = rec(0, kr, kb, new StringBuilder(s)); System.out.println(res); } private int rec(int cur, int kr, int kb, StringBuilder s){ if(s.length()<=12) return 12; else if(ok(kr, kb, s)) return s.length(); else if(cur>=s.length()) return 0; StringBuilder sb = new StringBuilder(s); int res = 0; if(s.charAt(cur)=='W'){ res = Math.max(res, rec(cur+1, kr, kb, sb)); }else{ char c = sb.charAt(cur); sb.deleteCharAt(cur); res = Math.max(res, rec(cur, kr, kb, sb)); sb.insert(cur, c); res = Math.max(res, rec(cur+1, kr, kb, sb)); } return res; } private boolean ok(int kr, int kb, StringBuilder s) { for(int i=0;i<s.length();i++){ char c = s.charAt(i); if(c=='R' && i+kr<s.length() && s.charAt(i+kr)=='R') return false; else if(c=='B' && i+kb<s.length() && s.charAt(i+kb)=='B') return false; } return true; } }