結果

問題 No.2276 I Want AC
ユーザー tamato
提出日時 2023-04-21 21:29:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 531 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 81,980 KB
実行使用メモリ 95,832 KB
最終ジャッジ日時 2024-11-06 14:57:50
合計ジャッジ時間 6,500 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
mod = 998244353

N = int(input())
S = input().rstrip('\n')

T = []
for s in S:
    if s == "?":
        T.append("C")
    else:
        T.append(s)
T = "".join(T)
ans = 0
c = T.count("C")
for t in T:
    if t == "A":
        ans += c
    else:
        c -= 1
tmp = ans
c = T.count("C")
a = 0
for i, t in enumerate(T):
    s = S[i]
    if t == "C":
        c -= 1
    else:
        a += 1
    if s == "?":
        tmp += c
        tmp -= a
        ans = max(ans, tmp)
        a += 1
print(ans)
0