結果

問題 No.1951 消えたAGCT(2)
ユーザー titiatitia
提出日時 2022-05-20 23:57:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,257 bytes
コンパイル時間 983 ms
コンパイル使用メモリ 81,336 KB
実行使用メモリ 63,468 KB
最終ジャッジ日時 2023-10-20 14:53:31
合計ジャッジ時間 5,401 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,432 KB
testcase_01 AC 41 ms
55,432 KB
testcase_02 AC 42 ms
55,432 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import Counter

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

LEN=n+5

BIT=[0]*(LEN+1) # 1-indexedなtree. 配列BITの長さはLEN+1にしていることに注意。

def update(v,w): # index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v)) # v&(-v)で、最も下の立っているビット. 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v): # [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v)) # 自分より小さい自分の和を構成するノードへ. たとえばv=14→v=12へ
    return ANS

A=[ord(S[i])-65 for i in range(n)]
SA=0

AGCT=[0,2,6,19]

C=Counter(A)


ANS=0

while True:
    #print("SA",SA)
    count=0
    for c in C:
        if (c+SA)%26 in AGCT:
            count+=C[c]

    if count==0:
        print(ANS)
        break
    else:
        ANS+=1

    # ind-getvalue(ind)==count-1

    #print("count",count)

    OK=-1
    NG=n-1

    while NG>OK+1:
        mid=(OK+NG)//2

        if mid-getvalue(mid)>count-1:
            NG=mid
        else:
            OK=mid

    #print("OK",OK)
            
    update(OK+1,1)
            
    k=A[OK]
    C[k]-=1
    SA+=C[k]

#print(ANS)

    
0