結果

問題 No.2276 I Want AC
ユーザー とりゐとりゐ
提出日時 2023-04-21 22:57:49
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 677 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 258,720 KB
最終ジャッジ日時 2024-04-24 09:00:16
合計ジャッジ時間 32,065 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,352 KB
testcase_01 AC 41 ms
52,096 KB
testcase_02 AC 42 ms
51,968 KB
testcase_03 AC 41 ms
51,712 KB
testcase_04 AC 42 ms
52,096 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 40 ms
52,096 KB
testcase_09 AC 40 ms
51,968 KB
testcase_10 RE -
testcase_11 AC 280 ms
130,128 KB
testcase_12 AC 782 ms
208,644 KB
testcase_13 AC 264 ms
122,200 KB
testcase_14 AC 159 ms
93,296 KB
testcase_15 AC 448 ms
173,320 KB
testcase_16 AC 380 ms
145,680 KB
testcase_17 AC 707 ms
198,660 KB
testcase_18 AC 521 ms
181,176 KB
testcase_19 AC 79 ms
75,520 KB
testcase_20 AC 849 ms
215,324 KB
testcase_21 AC 341 ms
139,992 KB
testcase_22 AC 177 ms
103,876 KB
testcase_23 AC 881 ms
217,320 KB
testcase_24 AC 831 ms
216,844 KB
testcase_25 AC 887 ms
215,388 KB
testcase_26 AC 876 ms
203,752 KB
testcase_27 AC 839 ms
240,808 KB
testcase_28 AC 739 ms
191,248 KB
testcase_29 AC 647 ms
258,720 KB
testcase_30 AC 1,095 ms
239,956 KB
testcase_31 AC 551 ms
258,276 KB
testcase_32 AC 846 ms
201,448 KB
testcase_33 AC 1,123 ms
239,944 KB
testcase_34 AC 771 ms
215,940 KB
testcase_35 AC 59 ms
68,736 KB
testcase_36 AC 58 ms
68,608 KB
testcase_37 AC 710 ms
163,420 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 730 ms
217,980 KB
testcase_43 AC 715 ms
222,608 KB
testcase_44 AC 63 ms
70,784 KB
testcase_45 AC 875 ms
201,752 KB
testcase_46 AC 892 ms
241,864 KB
testcase_47 AC 315 ms
193,540 KB
testcase_48 AC 318 ms
193,680 KB
testcase_49 AC 842 ms
200,376 KB
testcase_50 AC 913 ms
242,940 KB
testcase_51 AC 808 ms
241,276 KB
testcase_52 AC 887 ms
241,644 KB
testcase_53 AC 959 ms
203,296 KB
testcase_54 AC 635 ms
201,912 KB
testcase_55 AC 613 ms
202,232 KB
testcase_56 AC 593 ms
200,928 KB
testcase_57 WA -
testcase_58 RE -
権限があれば一括ダウンロードができます

ソースコード

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(L,R+1):
    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