結果
問題 | No.2276 I Want AC |
ユーザー | chineristAC |
提出日時 | 2023-04-21 21:27:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 358 ms / 2,000 ms |
コード長 | 1,948 bytes |
コンパイル時間 | 159 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 142,356 KB |
最終ジャッジ日時 | 2024-11-06 14:55:52 |
合計ジャッジ時間 | 13,792 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
68,352 KB |
testcase_01 | AC | 68 ms
69,500 KB |
testcase_02 | AC | 67 ms
69,888 KB |
testcase_03 | AC | 67 ms
68,672 KB |
testcase_04 | AC | 68 ms
69,968 KB |
testcase_05 | AC | 70 ms
68,748 KB |
testcase_06 | AC | 66 ms
68,440 KB |
testcase_07 | AC | 69 ms
68,968 KB |
testcase_08 | AC | 67 ms
69,612 KB |
testcase_09 | AC | 66 ms
69,092 KB |
testcase_10 | AC | 68 ms
69,388 KB |
testcase_11 | AC | 139 ms
92,084 KB |
testcase_12 | AC | 254 ms
131,248 KB |
testcase_13 | AC | 138 ms
91,900 KB |
testcase_14 | AC | 119 ms
84,136 KB |
testcase_15 | AC | 182 ms
106,260 KB |
testcase_16 | AC | 177 ms
105,824 KB |
testcase_17 | AC | 280 ms
133,420 KB |
testcase_18 | AC | 204 ms
111,572 KB |
testcase_19 | AC | 102 ms
80,052 KB |
testcase_20 | AC | 321 ms
138,972 KB |
testcase_21 | AC | 169 ms
103,524 KB |
testcase_22 | AC | 126 ms
88,588 KB |
testcase_23 | AC | 273 ms
134,364 KB |
testcase_24 | AC | 272 ms
134,496 KB |
testcase_25 | AC | 275 ms
134,460 KB |
testcase_26 | AC | 320 ms
138,968 KB |
testcase_27 | AC | 309 ms
137,584 KB |
testcase_28 | AC | 255 ms
131,796 KB |
testcase_29 | AC | 234 ms
127,572 KB |
testcase_30 | AC | 288 ms
136,924 KB |
testcase_31 | AC | 193 ms
121,560 KB |
testcase_32 | AC | 302 ms
137,604 KB |
testcase_33 | AC | 288 ms
136,804 KB |
testcase_34 | AC | 326 ms
141,004 KB |
testcase_35 | AC | 152 ms
114,504 KB |
testcase_36 | AC | 153 ms
114,524 KB |
testcase_37 | AC | 355 ms
142,256 KB |
testcase_38 | AC | 152 ms
114,380 KB |
testcase_39 | AC | 153 ms
114,308 KB |
testcase_40 | AC | 154 ms
114,616 KB |
testcase_41 | AC | 155 ms
114,512 KB |
testcase_42 | AC | 358 ms
142,212 KB |
testcase_43 | AC | 356 ms
142,356 KB |
testcase_44 | AC | 155 ms
113,484 KB |
testcase_45 | AC | 299 ms
138,788 KB |
testcase_46 | AC | 309 ms
138,756 KB |
testcase_47 | AC | 155 ms
113,884 KB |
testcase_48 | AC | 156 ms
113,888 KB |
testcase_49 | AC | 293 ms
138,724 KB |
testcase_50 | AC | 298 ms
138,988 KB |
testcase_51 | AC | 302 ms
138,968 KB |
testcase_52 | AC | 312 ms
138,728 KB |
testcase_53 | AC | 301 ms
138,628 KB |
testcase_54 | AC | 234 ms
129,804 KB |
testcase_55 | AC | 208 ms
124,868 KB |
testcase_56 | AC | 195 ms
121,420 KB |
testcase_57 | AC | 183 ms
121,452 KB |
testcase_58 | AC | 191 ms
122,884 KB |
ソースコード
import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd,log from math import sqrt, ceil from bisect import bisect_left, bisect_right from typing import Iterable input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) class SegmentTree: def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num self.size = n for i in range(n): self.tree[self.num + i] = init_val[i] for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): k += self.num self.tree[k] = x while k > 1: k >>= 1 self.tree[k] = self.segfunc(self.tree[2*k], self.tree[2*k+1]) def query(self, l, r): if r==self.size: r = self.num res = self.ide_ele l += self.num r += self.num right = [] while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: right.append(self.tree[r-1]) l >>= 1 r >>= 1 for e in right[::-1]: res = self.segfunc(res,e) return res def merge(x,y): return (x[0]+y[0],x[1]+y[1],x[2]+y[2]+x[0]*y[1]) N = int(input()) S = [s for s in input()] idx = [i for i in range(N) if S[i]=="?"] init = [-1] * N for i in range(N): if S[i]=="A": init[i] = (1,0,0) else: init[i] = (0,1,0) seg = SegmentTree(init,merge,(0,0,0)) res = seg.tree[1][2] for i in idx: seg.update(i,(1,0,0)) res = max(res,seg.tree[1][2]) print(res)