結果

問題 No.2276 I Want AC
ユーザー とりゐとりゐ
提出日時 2023-04-21 23:02:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,116 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 258,768 KB
最終ジャッジ日時 2024-04-24 09:04:39
合計ジャッジ時間 30,646 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,224 KB
testcase_01 AC 41 ms
52,352 KB
testcase_02 AC 42 ms
52,096 KB
testcase_03 AC 41 ms
52,224 KB
testcase_04 AC 43 ms
52,224 KB
testcase_05 AC 42 ms
51,968 KB
testcase_06 AC 42 ms
51,968 KB
testcase_07 AC 42 ms
52,224 KB
testcase_08 AC 42 ms
52,096 KB
testcase_09 AC 41 ms
51,712 KB
testcase_10 AC 41 ms
51,712 KB
testcase_11 AC 274 ms
129,868 KB
testcase_12 AC 775 ms
208,776 KB
testcase_13 AC 288 ms
121,984 KB
testcase_14 AC 146 ms
92,672 KB
testcase_15 AC 455 ms
173,696 KB
testcase_16 AC 381 ms
145,296 KB
testcase_17 AC 665 ms
198,780 KB
testcase_18 AC 561 ms
181,192 KB
testcase_19 AC 78 ms
76,032 KB
testcase_20 AC 821 ms
215,580 KB
testcase_21 AC 323 ms
140,612 KB
testcase_22 AC 174 ms
103,736 KB
testcase_23 AC 874 ms
216,888 KB
testcase_24 AC 804 ms
217,120 KB
testcase_25 AC 936 ms
215,236 KB
testcase_26 AC 839 ms
203,436 KB
testcase_27 AC 801 ms
240,688 KB
testcase_28 AC 724 ms
190,840 KB
testcase_29 AC 660 ms
258,348 KB
testcase_30 AC 1,107 ms
238,824 KB
testcase_31 AC 568 ms
258,768 KB
testcase_32 AC 852 ms
201,484 KB
testcase_33 AC 1,116 ms
238,564 KB
testcase_34 AC 795 ms
216,428 KB
testcase_35 AC 58 ms
68,480 KB
testcase_36 AC 58 ms
68,480 KB
testcase_37 AC 708 ms
162,820 KB
testcase_38 AC 305 ms
219,596 KB
testcase_39 AC 242 ms
180,480 KB
testcase_40 AC 281 ms
180,480 KB
testcase_41 AC 313 ms
207,620 KB
testcase_42 AC 736 ms
218,116 KB
testcase_43 AC 699 ms
223,468 KB
testcase_44 AC 62 ms
71,040 KB
testcase_45 AC 847 ms
199,808 KB
testcase_46 AC 890 ms
241,476 KB
testcase_47 AC 302 ms
193,668 KB
testcase_48 AC 303 ms
193,936 KB
testcase_49 AC 802 ms
198,764 KB
testcase_50 AC 894 ms
243,000 KB
testcase_51 AC 777 ms
241,368 KB
testcase_52 AC 802 ms
241,504 KB
testcase_53 AC 895 ms
202,128 KB
testcase_54 AC 645 ms
202,160 KB
testcase_55 AC 605 ms
202,736 KB
testcase_56 AC 601 ms
197,852 KB
testcase_57 AC 505 ms
258,460 KB
testcase_58 AC 773 ms
186,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def count(t):
  A=0
  res=0
  for i in t:
    if i=='A':
      A+=1
    else:
      res+=A
  return res


def calc(mid):
  t=[]
  if mid==-1:
    x=-1
  elif mid==m:
    x=n
  else:
    x=B[mid]
  for i in range(n):
    if s[i]=='A' or (s[i]=='?' and i<=x):
      t.append('A')
    else:
      t.append('C')
  return count(t)
 

def ternary_search(L,R):
  # 準下凸関数の最小値
  while L+2<R:
    c1=L+(R-L)//3
    c2=R-(R-L)//3
    if calc(c1)>calc(c2):
      R=c2
    else:
      L=c1
  
  ans=0
  for i in range(L,R):
    ans=max(ans,calc(i))
  
  return ans

n=int(input())
s=list(input())
B=[]
for i in range(n):
  if s[i]=='?':
    B.append(i)

if len(B)==0:
  print(count(s))
  exit()

m=len(B)
print(ternary_search(-1,m))
0