結果

問題 No.2276 I Want AC
コンテスト
ユーザー LyricalMaestro
提出日時 2025-10-06 21:17:26
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 80 ms / 2,000 ms
+ 519µs
コード長 655 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 409 ms
コンパイル使用メモリ 95,724 KB
実行使用メモリ 83,840 KB
最終ジャッジ日時 2026-07-15 14:45:47
合計ジャッジ時間 6,994 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/2276




def main():
    N = int(input())
    S = input()

    # 全てAにした時の回答
    answer = 0
    a_num = 0
    for s in S:
        if s in ("A", "?"):
            a_num += 1
        else:
            answer += a_num

    max_answer = answer
    c_num = 0
    for s in reversed(S):
        if s == "?":
            a_num -= 1
            answer -= c_num
            answer += a_num
            c_num += 1
        elif s == "C":
            c_num += 1
        elif s == "A":
            a_num -= 1
        max_answer = max(max_answer, answer)
    print(max_answer)



if __name__ == "__main__":
    main()
0