結果

問題 No.2276 I Want AC
ユーザー FromBooskaFromBooska
提出日時 2023-06-06 20:15:59
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,741 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 80,536 KB
最終ジャッジ日時 2023-08-28 10:47:45
合計ジャッジ時間 15,301 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,520 KB
testcase_01 RE -
testcase_02 AC 72 ms
71,468 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 73 ms
71,268 KB
testcase_06 AC 73 ms
71,196 KB
testcase_07 AC 73 ms
71,308 KB
testcase_08 AC 72 ms
71,500 KB
testcase_09 AC 75 ms
71,348 KB
testcase_10 AC 76 ms
71,660 KB
testcase_11 AC 144 ms
76,112 KB
testcase_12 AC 290 ms
76,720 KB
testcase_13 AC 150 ms
76,284 KB
testcase_14 AC 111 ms
76,004 KB
testcase_15 AC 178 ms
76,140 KB
testcase_16 AC 172 ms
76,196 KB
testcase_17 AC 288 ms
76,576 KB
testcase_18 AC 223 ms
76,404 KB
testcase_19 AC 85 ms
75,600 KB
testcase_20 AC 317 ms
76,460 KB
testcase_21 AC 159 ms
76,176 KB
testcase_22 AC 110 ms
75,912 KB
testcase_23 AC 308 ms
76,292 KB
testcase_24 AC 331 ms
76,284 KB
testcase_25 AC 338 ms
76,292 KB
testcase_26 AC 330 ms
76,416 KB
testcase_27 AC 309 ms
76,308 KB
testcase_28 AC 254 ms
76,284 KB
testcase_29 AC 222 ms
76,456 KB
testcase_30 AC 296 ms
76,428 KB
testcase_31 AC 192 ms
76,448 KB
testcase_32 AC 312 ms
76,576 KB
testcase_33 AC 294 ms
76,464 KB
testcase_34 AC 313 ms
76,284 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 282 ms
76,196 KB
testcase_38 AC 98 ms
76,068 KB
testcase_39 AC 95 ms
76,176 KB
testcase_40 AC 109 ms
76,204 KB
testcase_41 AC 112 ms
76,248 KB
testcase_42 AC 285 ms
76,348 KB
testcase_43 AC 288 ms
76,588 KB
testcase_44 RE -
testcase_45 AC 319 ms
76,504 KB
testcase_46 AC 297 ms
76,456 KB
testcase_47 AC 113 ms
76,052 KB
testcase_48 AC 123 ms
76,296 KB
testcase_49 AC 324 ms
76,384 KB
testcase_50 AC 310 ms
76,280 KB
testcase_51 AC 300 ms
76,440 KB
testcase_52 AC 334 ms
76,456 KB
testcase_53 AC 322 ms
76,488 KB
testcase_54 AC 231 ms
76,440 KB
testcase_55 AC 209 ms
76,428 KB
testcase_56 AC 196 ms
76,424 KB
testcase_57 AC 151 ms
76,236 KB
testcase_58 AC 254 ms
76,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ?の前半は当然Aがいい、後半はCがいい
# それではどこまでAであるべきなのか、を探索する
# 入力例1からわかるが単調増加、単調減少ではないので三分探索
# 使っている三分探索が最低値探索なのでスコアをマイナスにして探索した

N = int(input())
S = input()
Q_count = S.count('?')

# 使っている三分探索が最低値探索用なのでマイナスのスコアとした
def check(X):
    q_count = 0
    a_count = 0
    score = 0
    for s in S:
        if s == 'A':
            a_count += 1
        elif s == 'C':
            score += a_count
        elif s == '?':
            if q_count < X:
                # deem as A
                a_count += 1
                q_count += 1
            else:
                # deem as C
                score += a_count
                q_count += 1
    return -score

#for x in range(Q_count+1):
#    print(x, check(x))

# 谷、つまり1極値を求める三分探索での解き方
# https://roiti46.hatenablog.com/entry/2015/04/29/yukicoder_No.198_%E3%82%AD%E3%83%A3%E3%83%B3%E3%83%87%E3%82%A3%E3%83%BC%E3%83%BB%E3%83%9C%E3%83%83%E3%82%AF%E3%82%B9%EF%BC%92
# https://qiita.com/ganyariya/items/1553ff2bf8d6d7789127

# 範囲に注意、ギリギリありえない値とする
left, right = -1, Q_count+1
while right-left > 2:
    left_mid, right_mid = (2*left+right)//3, (left+2*right)//3
    if check(left_mid) <= check(right_mid):
        # 右midの方が大きいから右を右midに変える
        right = right_mid
    else:
        left = left_mid

#print(left_mid, right_mid)

ans = min(check(left_mid), check(right_mid))
# leftとrightの間も入れる必要あるのか? ない
print(-ans)

0