結果

問題 No.2276 I Want AC
ユーザー sotanishysotanishy
提出日時 2023-04-21 22:00:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 673 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,944 KB
実行使用メモリ 79,360 KB
最終ジャッジ日時 2024-04-24 08:08:37
合計ジャッジ時間 5,627 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,480 KB
testcase_01 AC 37 ms
52,224 KB
testcase_02 AC 37 ms
51,968 KB
testcase_03 AC 37 ms
52,224 KB
testcase_04 AC 38 ms
52,224 KB
testcase_05 AC 37 ms
52,096 KB
testcase_06 AC 37 ms
51,840 KB
testcase_07 AC 37 ms
51,968 KB
testcase_08 AC 36 ms
51,840 KB
testcase_09 AC 40 ms
51,712 KB
testcase_10 AC 37 ms
52,224 KB
testcase_11 AC 70 ms
71,936 KB
testcase_12 AC 84 ms
78,720 KB
testcase_13 AC 66 ms
71,040 KB
testcase_14 AC 62 ms
67,584 KB
testcase_15 AC 70 ms
73,984 KB
testcase_16 AC 72 ms
74,624 KB
testcase_17 AC 76 ms
78,336 KB
testcase_18 AC 78 ms
77,696 KB
testcase_19 AC 61 ms
66,304 KB
testcase_20 AC 80 ms
78,848 KB
testcase_21 AC 68 ms
72,320 KB
testcase_22 AC 65 ms
69,120 KB
testcase_23 AC 83 ms
79,232 KB
testcase_24 AC 82 ms
79,104 KB
testcase_25 AC 85 ms
78,976 KB
testcase_26 AC 81 ms
78,848 KB
testcase_27 AC 82 ms
79,232 KB
testcase_28 AC 80 ms
78,848 KB
testcase_29 AC 77 ms
78,976 KB
testcase_30 AC 78 ms
78,976 KB
testcase_31 AC 76 ms
78,848 KB
testcase_32 AC 83 ms
78,848 KB
testcase_33 AC 77 ms
79,232 KB
testcase_34 AC 78 ms
79,360 KB
testcase_35 AC 55 ms
64,512 KB
testcase_36 AC 55 ms
64,896 KB
testcase_37 AC 60 ms
66,304 KB
testcase_38 AC 68 ms
79,232 KB
testcase_39 AC 68 ms
79,360 KB
testcase_40 AC 74 ms
78,976 KB
testcase_41 AC 72 ms
79,104 KB
testcase_42 AC 73 ms
78,976 KB
testcase_43 AC 71 ms
79,232 KB
testcase_44 AC 82 ms
78,720 KB
testcase_45 AC 79 ms
79,104 KB
testcase_46 AC 80 ms
78,848 KB
testcase_47 AC 80 ms
79,104 KB
testcase_48 AC 79 ms
79,104 KB
testcase_49 AC 83 ms
79,232 KB
testcase_50 AC 77 ms
78,848 KB
testcase_51 AC 79 ms
79,104 KB
testcase_52 AC 77 ms
78,848 KB
testcase_53 AC 81 ms
79,232 KB
testcase_54 AC 80 ms
78,976 KB
testcase_55 AC 81 ms
79,104 KB
testcase_56 AC 73 ms
78,848 KB
testcase_57 AC 65 ms
68,736 KB
testcase_58 AC 80 ms
78,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
S = input().rstrip()


right = [0] * (N+1)
cnt = 0
for i in range(N)[::-1]:
    right[i] = right[i+1]
    if S[i] == 'A':
        right[i] += cnt
    else:
        cnt += 1


left = [0] * (N+1)
cnt = 0
for i in range(N):
    left[i+1] = left[i]
    if S[i] == 'C':
        left[i+1] += cnt
    else:
        cnt += 1

ans = 0
A = 0
C = 0
for c in S:
    if c != 'A':
        C += 1

for i in range(N+1):
    ans = max(ans, left[i] + right[i] + A * C)
    if i < N:
        if S[i] == 'A':
            A += 1
        elif S[i] == '?':
            A += 1
            C -= 1
        else:
            C -= 1

print(ans)
0