結果

問題 No.2276 I Want AC
ユーザー tentententen
提出日時 2023-12-12 08:24:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 2,181 bytes
コンパイル時間 3,040 ms
コンパイル使用メモリ 90,016 KB
実行使用メモリ 56,036 KB
最終ジャッジ日時 2023-12-12 08:24:32
合計ジャッジ時間 12,433 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,980 KB
testcase_01 AC 55 ms
53,980 KB
testcase_02 AC 54 ms
54,016 KB
testcase_03 AC 53 ms
51,980 KB
testcase_04 AC 55 ms
53,980 KB
testcase_05 AC 54 ms
53,984 KB
testcase_06 AC 55 ms
53,988 KB
testcase_07 AC 53 ms
53,992 KB
testcase_08 AC 53 ms
53,944 KB
testcase_09 AC 53 ms
53,996 KB
testcase_10 AC 53 ms
53,984 KB
testcase_11 AC 86 ms
55,420 KB
testcase_12 AC 116 ms
55,900 KB
testcase_13 AC 86 ms
55,132 KB
testcase_14 AC 71 ms
54,500 KB
testcase_15 AC 94 ms
55,664 KB
testcase_16 AC 100 ms
55,428 KB
testcase_17 AC 116 ms
55,776 KB
testcase_18 AC 108 ms
55,780 KB
testcase_19 AC 56 ms
53,972 KB
testcase_20 AC 121 ms
56,036 KB
testcase_21 AC 98 ms
55,548 KB
testcase_22 AC 70 ms
54,612 KB
testcase_23 AC 121 ms
55,784 KB
testcase_24 AC 117 ms
55,780 KB
testcase_25 AC 128 ms
55,800 KB
testcase_26 AC 118 ms
55,824 KB
testcase_27 AC 119 ms
55,784 KB
testcase_28 AC 119 ms
55,660 KB
testcase_29 AC 106 ms
55,788 KB
testcase_30 AC 122 ms
55,804 KB
testcase_31 AC 116 ms
55,804 KB
testcase_32 AC 118 ms
55,764 KB
testcase_33 AC 123 ms
55,784 KB
testcase_34 AC 125 ms
53,912 KB
testcase_35 AC 117 ms
55,908 KB
testcase_36 AC 118 ms
55,796 KB
testcase_37 AC 119 ms
55,788 KB
testcase_38 AC 106 ms
53,936 KB
testcase_39 AC 114 ms
55,908 KB
testcase_40 AC 112 ms
55,516 KB
testcase_41 AC 115 ms
55,784 KB
testcase_42 AC 123 ms
55,864 KB
testcase_43 AC 120 ms
53,820 KB
testcase_44 AC 120 ms
56,000 KB
testcase_45 AC 118 ms
55,780 KB
testcase_46 AC 116 ms
55,520 KB
testcase_47 AC 116 ms
55,780 KB
testcase_48 AC 106 ms
55,780 KB
testcase_49 AC 120 ms
55,784 KB
testcase_50 AC 122 ms
55,928 KB
testcase_51 AC 116 ms
56,012 KB
testcase_52 AC 119 ms
55,788 KB
testcase_53 AC 120 ms
55,900 KB
testcase_54 AC 115 ms
55,808 KB
testcase_55 AC 118 ms
55,912 KB
testcase_56 AC 113 ms
55,796 KB
testcase_57 AC 112 ms
55,908 KB
testcase_58 AC 111 ms
55,784 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 aCount = 0;
        long current = 0;
        for (char c : inputs) {
            if (c == 'C') {
                current += aCount;
            } else {
                aCount++;
            }
        }
        long ans = current;
        int cCount = 0;
        for (int i = n - 1; i >= 0; i--) {
            if (inputs[i] == 'A') {
                aCount--;
            } else if (inputs[i] == 'C') {
                cCount++;
            } else {
                aCount--;
                current -= cCount;
                current += aCount;
                cCount++;
                ans = Math.max(ans, current);
            }
        }
        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