結果

問題 No.2276 I Want AC
ユーザー tentententen
提出日時 2024-04-03 11:00:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,793 bytes
コンパイル時間 2,496 ms
コンパイル使用メモリ 78,032 KB
実行使用メモリ 56,136 KB
最終ジャッジ日時 2024-04-03 11:00:22
合計ジャッジ時間 12,450 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,972 KB
testcase_01 AC 51 ms
51,968 KB
testcase_02 AC 52 ms
53,976 KB
testcase_03 AC 52 ms
53,980 KB
testcase_04 AC 52 ms
54,000 KB
testcase_05 AC 52 ms
53,992 KB
testcase_06 AC 52 ms
53,980 KB
testcase_07 AC 52 ms
53,992 KB
testcase_08 AC 53 ms
53,996 KB
testcase_09 AC 55 ms
53,984 KB
testcase_10 AC 52 ms
53,976 KB
testcase_11 AC 87 ms
55,004 KB
testcase_12 AC 114 ms
55,652 KB
testcase_13 AC 73 ms
54,896 KB
testcase_14 AC 65 ms
54,252 KB
testcase_15 AC 98 ms
55,292 KB
testcase_16 AC 83 ms
55,148 KB
testcase_17 AC 112 ms
55,656 KB
testcase_18 AC 106 ms
55,480 KB
testcase_19 AC 54 ms
53,992 KB
testcase_20 AC 113 ms
55,412 KB
testcase_21 AC 96 ms
55,528 KB
testcase_22 AC 68 ms
54,376 KB
testcase_23 AC 114 ms
55,672 KB
testcase_24 AC 117 ms
55,764 KB
testcase_25 AC 118 ms
55,664 KB
testcase_26 AC 104 ms
55,904 KB
testcase_27 AC 114 ms
55,648 KB
testcase_28 AC 113 ms
55,660 KB
testcase_29 AC 119 ms
55,644 KB
testcase_30 AC 118 ms
55,756 KB
testcase_31 AC 112 ms
55,664 KB
testcase_32 AC 118 ms
55,784 KB
testcase_33 AC 115 ms
55,792 KB
testcase_34 AC 114 ms
55,896 KB
testcase_35 AC 112 ms
55,640 KB
testcase_36 AC 110 ms
55,528 KB
testcase_37 AC 113 ms
55,656 KB
testcase_38 AC 113 ms
55,608 KB
testcase_39 AC 105 ms
55,768 KB
testcase_40 AC 117 ms
55,660 KB
testcase_41 AC 111 ms
55,400 KB
testcase_42 AC 110 ms
55,648 KB
testcase_43 AC 111 ms
55,652 KB
testcase_44 AC 120 ms
55,672 KB
testcase_45 AC 117 ms
55,904 KB
testcase_46 AC 112 ms
55,524 KB
testcase_47 AC 117 ms
55,676 KB
testcase_48 AC 114 ms
55,660 KB
testcase_49 AC 114 ms
55,544 KB
testcase_50 AC 118 ms
55,548 KB
testcase_51 AC 114 ms
55,672 KB
testcase_52 AC 111 ms
55,660 KB
testcase_53 AC 114 ms
55,392 KB
testcase_54 AC 113 ms
55,660 KB
testcase_55 AC 113 ms
55,528 KB
testcase_56 AC 113 ms
56,136 KB
testcase_57 AC 111 ms
55,792 KB
testcase_58 AC 112 ms
55,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
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 a = 0;
        long total = 0;
        for (int i = 0; i < n; i++) {
            if (inputs[i] == 'C') {
                total += a;
            } else {
                a++;
            }
        }
        long ans = total;
        int c = 0;
        for (int i = n - 1; i >= 0; i--) {
            if (inputs[i] == 'C') {
                c++;
            } else if (inputs[i] == 'A') {
                a--;
            } else {
                total -= c;
                a--;
                c++;
                total += a;
                ans = Math.max(ans, total);
            }
        }
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0