結果

問題 No.2276 I Want AC
ユーザー Shirotsume
提出日時 2023-04-21 22:05:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 633 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 76,544 KB
最終ジャッジ日時 2024-11-06 15:34:52
合計ジャッジ時間 6,009 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque, Counter
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

n = ii()
s = input()
counta = 0
countc = 0
ans = 0
for v in s:
    if v == 'C' or v == '?':
        ans += counta
        countc += 1
    else:
        counta += 1

counta = 0
now = ans
for v in s:
    if v == 'A':
        counta += 1
    if v == 'C':
        countc -= 1
    if v == '?':
        countc -= 1
        now += countc
        now -= counta
        ans = max(ans, now)
        counta += 1
print(ans)

0