結果

問題 No.1951 消えたAGCT(2)
ユーザー titiatitia
提出日時 2022-05-21 00:07:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,236 ms / 3,000 ms
コード長 1,128 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 81,560 KB
実行使用メモリ 93,724 KB
最終ジャッジ日時 2023-10-20 15:02:43
合計ジャッジ時間 13,524 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,508 KB
testcase_01 AC 42 ms
55,508 KB
testcase_02 AC 42 ms
55,508 KB
testcase_03 AC 43 ms
55,508 KB
testcase_04 AC 43 ms
55,508 KB
testcase_05 AC 43 ms
55,508 KB
testcase_06 AC 42 ms
55,508 KB
testcase_07 AC 43 ms
55,508 KB
testcase_08 AC 98 ms
87,692 KB
testcase_09 AC 74 ms
82,892 KB
testcase_10 AC 72 ms
82,892 KB
testcase_11 AC 72 ms
82,892 KB
testcase_12 AC 71 ms
76,948 KB
testcase_13 AC 96 ms
76,280 KB
testcase_14 AC 1,135 ms
92,064 KB
testcase_15 AC 927 ms
89,036 KB
testcase_16 AC 989 ms
88,752 KB
testcase_17 AC 1,229 ms
93,412 KB
testcase_18 AC 1,236 ms
92,336 KB
testcase_19 AC 1,223 ms
93,148 KB
testcase_20 AC 1,182 ms
92,620 KB
testcase_21 AC 119 ms
89,416 KB
testcase_22 AC 120 ms
89,356 KB
testcase_23 AC 130 ms
89,528 KB
testcase_24 AC 132 ms
89,052 KB
testcase_25 AC 127 ms
89,844 KB
testcase_26 AC 1,198 ms
93,724 KB
testcase_27 AC 1,190 ms
92,356 KB
権限があれば一括ダウンロードができます

ソースコード

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(sorted(A))

ANS=0

while True:
    count=0
    for x in AGCT:
        count+=C[(x-SA)%26]

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

    OK=0
    NG=n

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

        if mid-getvalue(mid)>count-1:
            NG=mid
        else:
            OK=mid
            
    update(OK+1,1)
            
    k=A[OK]
    C[k]-=1
    SA+=C[k]
    SA%=26
0