結果
問題 | No.2276 I Want AC |
ユーザー | shotoyoo |
提出日時 | 2023-04-21 21:38:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 117 ms / 2,000 ms |
コード長 | 1,246 bytes |
コンパイル時間 | 442 ms |
コンパイル使用メモリ | 82,488 KB |
実行使用メモリ | 118,016 KB |
最終ジャッジ日時 | 2024-11-06 15:08:19 |
合計ジャッジ時間 | 6,462 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
54,016 KB |
testcase_01 | AC | 46 ms
54,272 KB |
testcase_02 | AC | 46 ms
54,144 KB |
testcase_03 | AC | 48 ms
54,272 KB |
testcase_04 | AC | 47 ms
54,016 KB |
testcase_05 | AC | 47 ms
54,400 KB |
testcase_06 | AC | 47 ms
53,888 KB |
testcase_07 | AC | 46 ms
54,144 KB |
testcase_08 | AC | 47 ms
54,144 KB |
testcase_09 | AC | 47 ms
54,016 KB |
testcase_10 | AC | 47 ms
54,272 KB |
testcase_11 | AC | 71 ms
70,784 KB |
testcase_12 | AC | 84 ms
82,688 KB |
testcase_13 | AC | 72 ms
71,040 KB |
testcase_14 | AC | 69 ms
69,504 KB |
testcase_15 | AC | 75 ms
75,904 KB |
testcase_16 | AC | 74 ms
73,984 KB |
testcase_17 | AC | 88 ms
88,832 KB |
testcase_18 | AC | 81 ms
80,128 KB |
testcase_19 | AC | 66 ms
66,176 KB |
testcase_20 | AC | 97 ms
98,432 KB |
testcase_21 | AC | 72 ms
72,192 KB |
testcase_22 | AC | 68 ms
68,480 KB |
testcase_23 | AC | 88 ms
84,992 KB |
testcase_24 | AC | 87 ms
85,248 KB |
testcase_25 | AC | 87 ms
85,120 KB |
testcase_26 | AC | 95 ms
94,976 KB |
testcase_27 | AC | 90 ms
91,776 KB |
testcase_28 | AC | 81 ms
79,488 KB |
testcase_29 | AC | 75 ms
74,624 KB |
testcase_30 | AC | 90 ms
88,832 KB |
testcase_31 | AC | 70 ms
69,120 KB |
testcase_32 | AC | 94 ms
92,288 KB |
testcase_33 | AC | 90 ms
88,960 KB |
testcase_34 | AC | 99 ms
101,632 KB |
testcase_35 | AC | 55 ms
62,592 KB |
testcase_36 | AC | 55 ms
62,592 KB |
testcase_37 | AC | 108 ms
114,816 KB |
testcase_38 | AC | 57 ms
63,616 KB |
testcase_39 | AC | 57 ms
63,488 KB |
testcase_40 | AC | 57 ms
63,360 KB |
testcase_41 | AC | 57 ms
63,488 KB |
testcase_42 | AC | 115 ms
117,120 KB |
testcase_43 | AC | 117 ms
118,016 KB |
testcase_44 | AC | 58 ms
63,616 KB |
testcase_45 | AC | 90 ms
91,520 KB |
testcase_46 | AC | 89 ms
90,752 KB |
testcase_47 | AC | 59 ms
63,488 KB |
testcase_48 | AC | 59 ms
63,488 KB |
testcase_49 | AC | 96 ms
92,928 KB |
testcase_50 | AC | 97 ms
93,312 KB |
testcase_51 | AC | 96 ms
93,312 KB |
testcase_52 | AC | 96 ms
92,928 KB |
testcase_53 | AC | 92 ms
91,904 KB |
testcase_54 | AC | 80 ms
78,080 KB |
testcase_55 | AC | 76 ms
73,472 KB |
testcase_56 | AC | 80 ms
70,272 KB |
testcase_57 | AC | 68 ms
68,992 KB |
testcase_58 | AC | 71 ms
70,656 KB |
ソースコード
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)