結果

問題 No.2276 I Want AC
ユーザー tentententen
提出日時 2023-07-26 18:49:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 2,170 bytes
コンパイル時間 3,669 ms
コンパイル使用メモリ 91,396 KB
実行使用メモリ 54,052 KB
最終ジャッジ日時 2024-04-14 08:20:42
合計ジャッジ時間 11,150 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
50,500 KB
testcase_01 AC 54 ms
50,156 KB
testcase_02 AC 53 ms
50,408 KB
testcase_03 AC 52 ms
50,024 KB
testcase_04 AC 54 ms
50,412 KB
testcase_05 AC 54 ms
50,408 KB
testcase_06 AC 53 ms
50,412 KB
testcase_07 AC 53 ms
50,160 KB
testcase_08 AC 52 ms
50,440 KB
testcase_09 AC 52 ms
50,380 KB
testcase_10 AC 53 ms
50,448 KB
testcase_11 AC 73 ms
51,300 KB
testcase_12 AC 115 ms
51,924 KB
testcase_13 AC 73 ms
51,316 KB
testcase_14 AC 66 ms
50,816 KB
testcase_15 AC 94 ms
52,084 KB
testcase_16 AC 100 ms
51,780 KB
testcase_17 AC 118 ms
52,132 KB
testcase_18 AC 101 ms
52,008 KB
testcase_19 AC 55 ms
50,424 KB
testcase_20 AC 119 ms
52,340 KB
testcase_21 AC 86 ms
51,616 KB
testcase_22 AC 71 ms
51,032 KB
testcase_23 AC 117 ms
52,116 KB
testcase_24 AC 117 ms
51,952 KB
testcase_25 AC 120 ms
52,284 KB
testcase_26 AC 124 ms
52,128 KB
testcase_27 AC 119 ms
52,188 KB
testcase_28 AC 118 ms
52,116 KB
testcase_29 AC 115 ms
51,892 KB
testcase_30 AC 114 ms
51,796 KB
testcase_31 AC 113 ms
52,280 KB
testcase_32 AC 110 ms
54,052 KB
testcase_33 AC 120 ms
52,236 KB
testcase_34 AC 113 ms
52,072 KB
testcase_35 AC 112 ms
52,120 KB
testcase_36 AC 108 ms
52,072 KB
testcase_37 AC 113 ms
52,128 KB
testcase_38 AC 113 ms
51,844 KB
testcase_39 AC 114 ms
52,140 KB
testcase_40 AC 114 ms
52,188 KB
testcase_41 AC 112 ms
52,044 KB
testcase_42 AC 117 ms
51,940 KB
testcase_43 AC 117 ms
52,332 KB
testcase_44 AC 116 ms
52,192 KB
testcase_45 AC 114 ms
52,308 KB
testcase_46 AC 115 ms
52,172 KB
testcase_47 AC 119 ms
51,984 KB
testcase_48 AC 119 ms
52,232 KB
testcase_49 AC 118 ms
52,124 KB
testcase_50 AC 106 ms
52,156 KB
testcase_51 AC 115 ms
52,240 KB
testcase_52 AC 115 ms
51,912 KB
testcase_53 AC 117 ms
52,216 KB
testcase_54 AC 114 ms
52,040 KB
testcase_55 AC 116 ms
52,048 KB
testcase_56 AC 115 ms
52,076 KB
testcase_57 AC 116 ms
52,096 KB
testcase_58 AC 111 ms
52,308 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 n = sc.nextInt();
        char[] inputs = sc.next().toCharArray();
        int frontA = 0;
        long current = 0;
        for (int i = 0; i < n; i++) {
            if (inputs[i] == 'C') {
                current += frontA;
            } else {
                frontA++;
            }
        }
        int rearC = 0;
        long ans = current;
        for (int i = n - 1; i >= 0; i--) {
            if (inputs[i] == 'A') {
                frontA--;
            } else if (inputs[i] == 'C') {
                rearC++;
            } else {
                frontA--;
                current += frontA - rearC;
                ans = Math.max(ans, current);
                rearC++;
            }
        }
        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