結果

問題 No.1951 消えたAGCT(2)
ユーザー siganaisiganai
提出日時 2022-05-26 16:52:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 464 ms / 3,000 ms
コード長 1,679 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 81,888 KB
実行使用メモリ 81,756 KB
最終ジャッジ日時 2023-10-20 19:29:55
合計ジャッジ時間 7,298 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
63,544 KB
testcase_01 AC 57 ms
63,544 KB
testcase_02 AC 59 ms
63,544 KB
testcase_03 AC 57 ms
63,544 KB
testcase_04 AC 57 ms
63,544 KB
testcase_05 AC 57 ms
63,544 KB
testcase_06 AC 57 ms
63,544 KB
testcase_07 AC 59 ms
63,544 KB
testcase_08 AC 135 ms
81,340 KB
testcase_09 AC 128 ms
81,596 KB
testcase_10 AC 131 ms
81,340 KB
testcase_11 AC 129 ms
81,596 KB
testcase_12 AC 110 ms
79,680 KB
testcase_13 AC 95 ms
77,440 KB
testcase_14 AC 405 ms
81,524 KB
testcase_15 AC 372 ms
80,944 KB
testcase_16 AC 391 ms
81,052 KB
testcase_17 AC 464 ms
81,752 KB
testcase_18 AC 458 ms
81,756 KB
testcase_19 AC 456 ms
81,752 KB
testcase_20 AC 459 ms
81,756 KB
testcase_21 AC 129 ms
81,340 KB
testcase_22 AC 131 ms
81,340 KB
testcase_23 AC 137 ms
81,340 KB
testcase_24 AC 133 ms
81,340 KB
testcase_25 AC 132 ms
81,340 KB
testcase_26 AC 429 ms
81,752 KB
testcase_27 AC 463 ms
81,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env PyPy3

from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
from heapq import *
import functools

mod=10 ** 9 + 7

import sys
input = sys.stdin.readline
class Bit:#0-indexed を 1-indexedに変換するので、0-indexedを入れる
    def __init__(self, n):
        self.size = n + 1
        self.tree = [0] * (n + 2)
        self.depth = (n + 1).bit_length()

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
    def sum(self, i):
        i += 1
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos, sum_
n = int(input())
s = input().rstrip()
dele = [0,ord('C') - ord('A'),ord('G') - ord('A'),ord('T') - ord('A')]
li = [0] * 26
for ss in s:
    li[ord(ss) - ord('A')] += 1
ans = 0
bit = Bit(n)
for i in range(n):
    bit.add(i,1)
while li[dele[0]] + li[dele[1]] + li[dele[2]] + li[dele[3]]:
    c = li[dele[0]] + li[dele[1]] + li[dele[2]] + li[dele[3]]
    idx,_ = bit.lower_bound(c)
    li[ord(s[idx]) - ord('A')] -= 1
    bit.add(idx,-1)
    for i in range(4):
        dele[i] -= li[ord(s[idx]) - ord('A')]
        dele[i] %= 26
    ans += 1
print(ans)
0