結果

問題 No.38 赤青白ブロック
ユーザー tentententen
提出日時 2023-01-26 11:09:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 259 ms / 5,000 ms
コード長 2,906 bytes
コンパイル時間 4,051 ms
コンパイル使用メモリ 80,236 KB
実行使用メモリ 54,120 KB
最終ジャッジ日時 2023-09-09 14:11:38
合計ジャッジ時間 11,564 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 235 ms
52,736 KB
testcase_01 AC 199 ms
52,344 KB
testcase_02 AC 205 ms
52,588 KB
testcase_03 AC 201 ms
52,340 KB
testcase_04 AC 172 ms
52,676 KB
testcase_05 AC 242 ms
52,776 KB
testcase_06 AC 169 ms
52,508 KB
testcase_07 AC 197 ms
52,988 KB
testcase_08 AC 244 ms
52,592 KB
testcase_09 AC 189 ms
52,268 KB
testcase_10 AC 222 ms
51,664 KB
testcase_11 AC 242 ms
52,700 KB
testcase_12 AC 216 ms
52,328 KB
testcase_13 AC 242 ms
52,508 KB
testcase_14 AC 192 ms
52,400 KB
testcase_15 AC 238 ms
52,220 KB
testcase_16 AC 141 ms
52,964 KB
testcase_17 AC 227 ms
52,776 KB
testcase_18 AC 259 ms
52,912 KB
testcase_19 AC 227 ms
52,748 KB
testcase_20 AC 243 ms
54,120 KB
testcase_21 AC 212 ms
52,540 KB
testcase_22 AC 207 ms
52,472 KB
testcase_23 AC 243 ms
52,600 KB
testcase_24 AC 169 ms
52,476 KB
testcase_25 AC 226 ms
52,776 KB
testcase_26 AC 224 ms
52,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int kr = sc.nextInt();
        int kb = sc.nextInt();
        char[] inputs = sc.next().toCharArray();
        int[] idxes = new int[inputs.length];
        int counter = 0;
        for (int i = 0; i < inputs.length; i++) {
            if (inputs[i] == 'W') {
                idxes[i] = -1;
            } else {
                idxes[i] = counter++;
            }
        }
        int ans = 0;
        char[] tmp = new char[inputs.length];
        for (int i = 0; i < (1 << counter); i++) {
            int k = 0;
            boolean enable = true;
            for (int j = 0; j < inputs.length; j++) {
                if (idxes[j] == -1) {
                    tmp[k++] = 'W';
                } else {
                    if ((i & (1 << idxes[j])) == 0) {
                        continue;
                    }
                    if (inputs[j] == 'R') {
                        if (k - kr >= 0 && tmp[k - kr] == 'R') {
                            enable = false;
                            break;
                        }
                        tmp[k++] = 'R';
                    } else {
                        if (k - kb >= 0 && tmp[k - kb] == 'B') {
                            enable = false;
                            break;
                        }
                        tmp[k++] = 'B';
                    }
                }
            }
            if (enable) {
                ans = Math.max(ans, k);
            }
        }
        System.out.println(ans);
    }
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0