結果

問題 No.1951 消えたAGCT(2)
ユーザー 👑 rin204rin204
提出日時 2022-05-20 23:02:50
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 377 ms / 3,000 ms
コード長 1,957 bytes
コンパイル時間 1,176 ms
コンパイル使用メモリ 81,668 KB
実行使用メモリ 84,040 KB
最終ジャッジ日時 2023-10-20 13:56:13
合計ジャッジ時間 6,560 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,472 KB
testcase_01 AC 38 ms
53,472 KB
testcase_02 AC 38 ms
53,472 KB
testcase_03 AC 38 ms
53,472 KB
testcase_04 AC 38 ms
53,472 KB
testcase_05 AC 38 ms
53,472 KB
testcase_06 AC 39 ms
53,472 KB
testcase_07 AC 39 ms
53,472 KB
testcase_08 AC 112 ms
83,808 KB
testcase_09 AC 113 ms
83,808 KB
testcase_10 AC 111 ms
83,812 KB
testcase_11 AC 113 ms
83,808 KB
testcase_12 AC 89 ms
80,600 KB
testcase_13 AC 76 ms
75,724 KB
testcase_14 AC 341 ms
83,488 KB
testcase_15 AC 287 ms
82,372 KB
testcase_16 AC 295 ms
82,676 KB
testcase_17 AC 352 ms
84,036 KB
testcase_18 AC 354 ms
84,032 KB
testcase_19 AC 377 ms
84,040 KB
testcase_20 AC 348 ms
84,036 KB
testcase_21 AC 118 ms
83,808 KB
testcase_22 AC 115 ms
83,808 KB
testcase_23 AC 114 ms
83,812 KB
testcase_24 AC 113 ms
83,804 KB
testcase_25 AC 112 ms
83,812 KB
testcase_26 AC 350 ms
84,032 KB
testcase_27 AC 366 ms
84,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
    def __init__(self, n):
        self.size = n
        self.n0 = 1 << (n.bit_length() - 1)
        self.tree = [0] * (n + 1)
    
    def range_sum(self, l, r):
        return self.sum(r - 1) - self.sum(l - 1)
        
    def sum(self, i):
        i += 1
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
        
    def get(self, i):
        return self.sum(i) - self.sum(i - 1)
 
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
         
    def lower_bound(self, x):
        pos = 0
        plus = self.n0
        tot = 0
        while plus > 0:
            if pos + plus <= self.size and self.tree[pos + plus] < x:
                x -= self.tree[pos + plus]
                pos += plus
            plus //= 2
        return pos

def stupid(S):
    ret = 0
    while 1:
        cnt = 0
        for s in S:
            if s in "AGCT":
                cnt += 1
        if cnt == 0:
            break
        ret += 1
        T = S[:cnt - 1] + S[cnt:]
        s = S[cnt - 1]
        cnt2 = 0
        for t in T:
            if t == s:
                cnt2 += 1
        S = []
        for s in T:
            p = ord(s) - 65
            p += cnt2
            p %= 26
            S.append(chr(p + 65))
        S = "".join(S)

    return ret

def solve(S):
    n = len(S)
    bit = Bit(n)
    for i in range(n):
        bit.add(i, 1)
    cnt = [0] * 26
    S = [ord(s) - 65 for s in S]
    for s in S:
        cnt[s] += 1
    rot = 0
    agct = [0, 6, 2, 19]
    ret = 0
    while 1:
        c1 = 0
        for i in agct:
            c1 += cnt[(i - rot) % 26]
        if c1 == 0:
            break
        ret += 1
        p = bit.lower_bound(c1)
        bit.add(p, -1)
        cnt[S[p]] -= 1
        c2 = cnt[S[p]]
        rot += c2
        
        
    return ret


n = int(input())
S = input()
print(solve(S))
0