結果

問題 No.2276 I Want AC
ユーザー tentententen
提出日時 2023-04-27 15:38:07
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,412 bytes
コンパイル時間 2,660 ms
コンパイル使用メモリ 91,772 KB
実行使用メモリ 49,048 KB
最終ジャッジ日時 2024-04-28 08:06:42
合計ジャッジ時間 7,132 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
42,508 KB
testcase_01 AC 45 ms
37,012 KB
testcase_02 AC 43 ms
37,040 KB
testcase_03 AC 44 ms
36,948 KB
testcase_04 AC 42 ms
36,708 KB
testcase_05 AC 44 ms
36,644 KB
testcase_06 AC 44 ms
36,756 KB
testcase_07 AC 43 ms
36,736 KB
testcase_08 AC 42 ms
36,948 KB
testcase_09 AC 44 ms
37,272 KB
testcase_10 AC 45 ms
36,936 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static long ans = 0;
    static char[] inputs;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        inputs = sc.next().toCharArray();
        aac(0, 0, 0);
        System.out.println(ans);
    }
    
    static void aac(int idx, long a, long value) {
        if (idx == inputs.length) {
            ans = Math.max(ans, value);
            return;
        }
        if (inputs[idx] == 'A') {
            aac(idx + 1, a + 1, value);
        } else if (inputs[idx] == 'C') {
            aac(idx + 1, a, value + a);
        } else {
            aac(idx + 1, a + 1, value);
            cac(idx + 1, a, value + a);
        }
    }
    
    static void cac(int idx, long a, long value) {
        if (idx == inputs.length) {
            ans = Math.max(ans, value);
            return;
        }
        if (inputs[idx] == 'A') {
            cac(idx + 1, a + 1, value);
        } else if (inputs[idx] == 'C') {
            cac(idx + 1, a, value + a);
        } else {
            cac(idx + 1, a, value + a);
        }
    }
}
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