結果
| 問題 |
No.2276 I Want AC
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2023-04-21 21:49:35 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 120 ms / 2,000 ms |
| コード長 | 1,003 bytes |
| コンパイル時間 | 2,999 ms |
| コンパイル使用メモリ | 77,364 KB |
| 実行使用メモリ | 54,092 KB |
| 最終ジャッジ日時 | 2024-11-06 15:17:53 |
| 合計ジャッジ時間 | 10,617 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 |
ソースコード
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
char[] s = br.readLine().toCharArray();
br.close();
int[] a = new int[n + 1];
for (int i = 0; i < n; i++) {
a[i + 1] = a[i];
if (s[i] == 'A') {
a[i + 1]++;
}
}
int[] c = new int[n + 1];
for (int i = n - 1; i >= 0; i--) {
c[i] = c[i + 1];
if (s[i] == 'C') {
c[i]++;
}
}
long val = 0;
int cnt = 0;
int cq = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'A') {
cnt++;
} else {
val += cnt;
cq++;
}
}
long ans = val;
cnt = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'A') {
cnt++;
} else if (s[i] == '?') {
val -= cnt;
cq--;
val += cq;
cnt++;
ans = Math.max(ans, val);
} else {
cq--;
}
}
System.out.println(ans);
}
}
ks2m