結果

問題 No.2276 I Want AC
ユーザー qibqib
提出日時 2023-04-22 23:30:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 479 bytes
コンパイル時間 370 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 95,744 KB
最終ジャッジ日時 2024-04-25 01:03:03
合計ジャッジ時間 9,445 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,712 KB
testcase_01 AC 41 ms
51,840 KB
testcase_02 AC 38 ms
51,840 KB
testcase_03 AC 41 ms
51,840 KB
testcase_04 AC 40 ms
51,968 KB
testcase_05 AC 41 ms
52,224 KB
testcase_06 AC 40 ms
52,096 KB
testcase_07 AC 41 ms
51,840 KB
testcase_08 AC 44 ms
51,712 KB
testcase_09 AC 45 ms
52,096 KB
testcase_10 AC 46 ms
52,224 KB
testcase_11 AC 103 ms
81,408 KB
testcase_12 AC 154 ms
93,056 KB
testcase_13 AC 98 ms
81,344 KB
testcase_14 AC 83 ms
78,080 KB
testcase_15 AC 109 ms
84,992 KB
testcase_16 AC 106 ms
84,224 KB
testcase_17 AC 135 ms
92,160 KB
testcase_18 AC 120 ms
87,936 KB
testcase_19 AC 66 ms
69,760 KB
testcase_20 AC 151 ms
94,720 KB
testcase_21 AC 105 ms
83,156 KB
testcase_22 AC 82 ms
78,080 KB
testcase_23 AC 153 ms
95,360 KB
testcase_24 AC 151 ms
95,376 KB
testcase_25 AC 153 ms
95,360 KB
testcase_26 AC 157 ms
95,320 KB
testcase_27 AC 160 ms
95,232 KB
testcase_28 AC 152 ms
95,268 KB
testcase_29 AC 147 ms
95,744 KB
testcase_30 AC 151 ms
95,104 KB
testcase_31 AC 144 ms
95,488 KB
testcase_32 AC 151 ms
95,360 KB
testcase_33 AC 154 ms
95,104 KB
testcase_34 AC 149 ms
95,404 KB
testcase_35 AC 140 ms
95,104 KB
testcase_36 AC 137 ms
95,484 KB
testcase_37 AC 145 ms
95,104 KB
testcase_38 AC 152 ms
95,232 KB
testcase_39 AC 153 ms
95,104 KB
testcase_40 AC 146 ms
95,732 KB
testcase_41 AC 142 ms
95,232 KB
testcase_42 AC 146 ms
95,232 KB
testcase_43 AC 145 ms
95,232 KB
testcase_44 AC 148 ms
95,104 KB
testcase_45 AC 150 ms
95,360 KB
testcase_46 AC 153 ms
95,260 KB
testcase_47 AC 148 ms
95,488 KB
testcase_48 AC 142 ms
95,192 KB
testcase_49 AC 150 ms
95,360 KB
testcase_50 AC 151 ms
95,696 KB
testcase_51 AC 158 ms
95,744 KB
testcase_52 AC 157 ms
95,360 KB
testcase_53 AC 154 ms
95,616 KB
testcase_54 AC 149 ms
95,620 KB
testcase_55 AC 150 ms
95,616 KB
testcase_56 AC 150 ms
95,232 KB
testcase_57 AC 150 ms
95,616 KB
testcase_58 AC 149 ms
95,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input()

idx = { "A": 0, "C": 1, "?": 2 }

dp = [[0 for _ in range(3)] for _ in range(n)]
for i in range(n - 2, -1, -1):
  for c in range(3):
    dp[i][c] = dp[i + 1][c]
  dp[i][idx[s[i + 1]]] += 1

cur = 0
for i in range(n):
  if s[i] == "A":
    cur += dp[i][1] + dp[i][2]

ans = cur
cnt = 0
for i in range(n):
  if s[i] == "?":
    cur -= cnt
    cur += dp[i][1] + dp[i][2]
    ans = max(ans, cur)
    cnt += 1
  elif s[i] == "A":
    cnt += 1

print(ans)
0