結果

問題 No.2276 I Want AC
ユーザー rlangevin
提出日時 2023-04-21 21:34:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 405 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 73,472 KB
最終ジャッジ日時 2024-11-06 15:03:27
合計ジャッジ時間 5,658 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = list(input())
ans = 0
cnt = 0
for i in range(N):
    if S[i] == "A" or S[i] == "?":
        cnt += 1
    else:
        ans += cnt
        
num = ans
cntC = 0
for i in range(N - 1, -1, -1):
    if S[i] == "?":
        cnt -= 1
        num += cnt
        num -= cntC
        cntC += 1
    elif S[i] == "C":
        cntC += 1
    else:
        cnt -= 1
    ans = max(ans, num)
print(ans)
0