結果

問題 No.2276 I Want AC
ユーザー とりゐとりゐ
提出日時 2023-04-21 22:59:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 691 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 258,512 KB
最終ジャッジ日時 2024-04-24 09:03:04
合計ジャッジ時間 30,621 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
51,968 KB
testcase_01 AC 41 ms
52,096 KB
testcase_02 AC 41 ms
51,712 KB
testcase_03 AC 40 ms
52,096 KB
testcase_04 AC 41 ms
52,096 KB
testcase_05 AC 41 ms
51,840 KB
testcase_06 WA -
testcase_07 AC 41 ms
52,224 KB
testcase_08 AC 41 ms
52,352 KB
testcase_09 AC 41 ms
51,712 KB
testcase_10 AC 43 ms
52,224 KB
testcase_11 AC 278 ms
130,008 KB
testcase_12 AC 786 ms
208,896 KB
testcase_13 AC 266 ms
124,392 KB
testcase_14 AC 157 ms
92,992 KB
testcase_15 AC 454 ms
173,532 KB
testcase_16 AC 387 ms
145,308 KB
testcase_17 AC 708 ms
198,524 KB
testcase_18 AC 525 ms
181,612 KB
testcase_19 AC 79 ms
75,776 KB
testcase_20 AC 854 ms
215,696 KB
testcase_21 AC 340 ms
140,332 KB
testcase_22 AC 175 ms
104,004 KB
testcase_23 AC 889 ms
216,892 KB
testcase_24 AC 811 ms
215,380 KB
testcase_25 AC 881 ms
215,120 KB
testcase_26 AC 865 ms
203,632 KB
testcase_27 AC 801 ms
241,188 KB
testcase_28 AC 729 ms
191,248 KB
testcase_29 AC 642 ms
258,228 KB
testcase_30 AC 1,090 ms
240,192 KB
testcase_31 AC 553 ms
258,244 KB
testcase_32 AC 847 ms
201,636 KB
testcase_33 AC 1,098 ms
240,460 KB
testcase_34 AC 745 ms
216,092 KB
testcase_35 AC 57 ms
68,608 KB
testcase_36 AC 56 ms
68,480 KB
testcase_37 AC 704 ms
163,548 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 274 ms
180,096 KB
testcase_41 AC 311 ms
207,096 KB
testcase_42 AC 727 ms
218,252 KB
testcase_43 AC 705 ms
222,856 KB
testcase_44 AC 62 ms
71,040 KB
testcase_45 AC 872 ms
202,000 KB
testcase_46 AC 886 ms
241,856 KB
testcase_47 AC 311 ms
193,800 KB
testcase_48 AC 313 ms
193,300 KB
testcase_49 AC 834 ms
200,512 KB
testcase_50 AC 918 ms
243,312 KB
testcase_51 AC 799 ms
241,672 KB
testcase_52 AC 830 ms
241,260 KB
testcase_53 AC 914 ms
203,168 KB
testcase_54 AC 637 ms
202,300 KB
testcase_55 AC 591 ms
202,740 KB
testcase_56 AC 585 ms
201,820 KB
testcase_57 WA -
testcase_58 AC 754 ms
186,896 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=[]
  for i in range(n):
    if s[i]=='A' or (s[i]=='?' and i<=B[mid]):
      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(max(L,0),min(R+1,m)):
    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