結果
問題 | No.1951 消えたAGCT(2) |
ユーザー | 👑 rin204 |
提出日時 | 2022-05-20 23:02:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 326 ms / 3,000 ms |
コード長 | 1,957 bytes |
コンパイル時間 | 511 ms |
コンパイル使用メモリ | 82,476 KB |
実行使用メモリ | 84,992 KB |
最終ジャッジ日時 | 2024-09-20 09:25:49 |
合計ジャッジ時間 | 5,307 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
53,308 KB |
testcase_01 | AC | 35 ms
53,028 KB |
testcase_02 | AC | 36 ms
53,140 KB |
testcase_03 | AC | 37 ms
53,452 KB |
testcase_04 | AC | 38 ms
54,360 KB |
testcase_05 | AC | 37 ms
52,396 KB |
testcase_06 | AC | 37 ms
52,624 KB |
testcase_07 | AC | 36 ms
52,948 KB |
testcase_08 | AC | 103 ms
83,952 KB |
testcase_09 | AC | 103 ms
83,852 KB |
testcase_10 | AC | 105 ms
84,040 KB |
testcase_11 | AC | 104 ms
84,000 KB |
testcase_12 | AC | 85 ms
80,820 KB |
testcase_13 | AC | 73 ms
76,144 KB |
testcase_14 | AC | 298 ms
83,816 KB |
testcase_15 | AC | 254 ms
82,972 KB |
testcase_16 | AC | 265 ms
82,984 KB |
testcase_17 | AC | 320 ms
84,508 KB |
testcase_18 | AC | 311 ms
84,112 KB |
testcase_19 | AC | 314 ms
84,180 KB |
testcase_20 | AC | 321 ms
84,432 KB |
testcase_21 | AC | 102 ms
84,232 KB |
testcase_22 | AC | 98 ms
83,948 KB |
testcase_23 | AC | 99 ms
83,948 KB |
testcase_24 | AC | 102 ms
84,044 KB |
testcase_25 | AC | 105 ms
84,248 KB |
testcase_26 | AC | 326 ms
84,992 KB |
testcase_27 | AC | 326 ms
84,492 KB |
ソースコード
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))