結果

問題 No.2276 I Want AC
ユーザー titia
提出日時 2023-04-22 00:27:40
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,034 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 23,780 KB
最終ジャッジ日時 2024-11-06 17:36:52
合計ジャッジ時間 43,402 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51 WA * 4 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
S=input().strip()

LIST=[]

for i in range(N):
    if S[i]=="?":
        LIST.append(i)

def score(A):
    ANS=0
    now=0

    for x in A:
        if x=="A":
            now+=1
        else:
            ANS+=now
    return ANS


MIN=0
MAX=len(LIST)-1

while MAX>MIN+1:
    l=(MIN+MAX)//2

    A=list(S)
    B=list(S)

    for i in range(len(LIST)):
        if i<=l:
            A[LIST[i]]="A"
        else:
            A[LIST[i]]="C"

        if i<=l+1:
            B[LIST[i]]="A"
        else:
            B[LIST[i]]="C"

    if score(A)<score(B):
        MIN=l+1
    elif score(A)>score(B):
        MAX=l
    else:
        MIN=l
        MAX=l+1

l=MIN
A=list(S)
B=list(S)

for i in range(len(LIST)):
    if i<=l:
        A[LIST[i]]="A"
    else:
        A[LIST[i]]="C"

    if i<=l+1:
        B[LIST[i]]="A"
    else:
        B[LIST[i]]="C"

if score(A)<score(B):
    MIN=l+1
elif score(A)>score(B):
    MAX=l
else:
    MIN=l
    MAX=l+1
        
print(max(score(A),score(B)))
0