結果

問題 No.2276 I Want AC
ユーザー shotoyooshotoyoo
提出日時 2023-04-21 21:38:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,246 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 118,016 KB
最終ジャッジ日時 2024-04-24 07:48:19
合計ジャッジ時間 6,342 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
54,272 KB
testcase_01 AC 47 ms
54,528 KB
testcase_02 AC 48 ms
54,528 KB
testcase_03 AC 46 ms
54,400 KB
testcase_04 AC 47 ms
54,144 KB
testcase_05 AC 48 ms
54,272 KB
testcase_06 AC 47 ms
54,400 KB
testcase_07 AC 46 ms
54,144 KB
testcase_08 AC 47 ms
54,144 KB
testcase_09 AC 47 ms
54,400 KB
testcase_10 AC 48 ms
54,272 KB
testcase_11 AC 71 ms
70,784 KB
testcase_12 AC 84 ms
82,944 KB
testcase_13 AC 69 ms
71,168 KB
testcase_14 AC 70 ms
69,632 KB
testcase_15 AC 75 ms
76,032 KB
testcase_16 AC 74 ms
74,240 KB
testcase_17 AC 88 ms
89,088 KB
testcase_18 AC 81 ms
80,384 KB
testcase_19 AC 66 ms
66,176 KB
testcase_20 AC 97 ms
98,432 KB
testcase_21 AC 73 ms
72,320 KB
testcase_22 AC 69 ms
68,352 KB
testcase_23 AC 87 ms
85,248 KB
testcase_24 AC 87 ms
85,376 KB
testcase_25 AC 87 ms
85,120 KB
testcase_26 AC 95 ms
95,232 KB
testcase_27 AC 94 ms
91,776 KB
testcase_28 AC 81 ms
79,872 KB
testcase_29 AC 76 ms
75,136 KB
testcase_30 AC 90 ms
89,216 KB
testcase_31 AC 70 ms
69,248 KB
testcase_32 AC 94 ms
92,288 KB
testcase_33 AC 89 ms
89,344 KB
testcase_34 AC 101 ms
102,144 KB
testcase_35 AC 60 ms
62,976 KB
testcase_36 AC 55 ms
62,720 KB
testcase_37 AC 111 ms
115,200 KB
testcase_38 AC 58 ms
63,872 KB
testcase_39 AC 58 ms
63,488 KB
testcase_40 AC 58 ms
63,872 KB
testcase_41 AC 57 ms
63,744 KB
testcase_42 AC 119 ms
117,248 KB
testcase_43 AC 121 ms
118,016 KB
testcase_44 AC 60 ms
63,744 KB
testcase_45 AC 91 ms
91,776 KB
testcase_46 AC 90 ms
91,520 KB
testcase_47 AC 60 ms
64,128 KB
testcase_48 AC 63 ms
64,000 KB
testcase_49 AC 96 ms
93,312 KB
testcase_50 AC 97 ms
93,440 KB
testcase_51 AC 98 ms
93,440 KB
testcase_52 AC 97 ms
93,184 KB
testcase_53 AC 93 ms
92,288 KB
testcase_54 AC 88 ms
78,080 KB
testcase_55 AC 78 ms
73,728 KB
testcase_56 AC 72 ms
70,400 KB
testcase_57 AC 70 ms
69,120 KB
testcase_58 AC 71 ms
70,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, random
input = lambda : sys.stdin.readline().rstrip()


write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18
LI = lambda : list(map(int, input().split())); II=lambda : int(input()); SI=lambda : [ord(c)-ord("a") for c in input()]
def debug(_l_):
    for s in _l_.split():
        print(f"{s}={eval(s)}", end=" ")
    print()
def dlist(*l, fill=0):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [dlist(*ll, fill=fill) for _ in range(l[0])]

n = int(input())
s = input()
a = [0]*n
index = []
vs0 = []
vs1 = []
v0 = v1 = 0
res = 0
for i in range(n):
    if s[i]=="C":
        a[i] = 1
        v1 += 1
        res += v0
    elif s[i]=="A":
        a[i] = 0
        v0 += 1
    else:
        a[i] = -1
        index.append(i)
        vs0.append(v0)
        vs1.append(v1)
s = len(index)
vs1 = [v1-v for v in vs1]
cum = [0]*(s+1)
cum1 = [0]*(s+1)
for i in range(s)[::-1]:
    cum[i] = cum[i+1] + vs0[i]
for i in range(s):
    cum1[i+1] = cum1[i] + vs1[i]
ans = -INF
for i in range(s+1):
    val = cum[i] + i * (s-i) + cum1[i]
    ans = max(val,ans)
print(ans+res)
0