結果
問題 | No.1943 消えたAGCT(1) |
ユーザー |
![]() |
提出日時 | 2025-03-20 20:29:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,078 ms / 2,000 ms |
コード長 | 1,910 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 82,396 KB |
実行使用メモリ | 89,932 KB |
最終ジャッジ日時 | 2025-03-20 20:30:16 |
合計ジャッジ時間 | 13,315 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
class FenwickTree:def __init__(self, size):self.n = sizeself.tree = [0] * (self.n + 2) # Using n+2 to avoid issues with 1-based indexingdef update_point(self, idx, delta):# Converts to 1-based index internallyidx += 1 # since input is 0-basedwhile idx <= self.n:self.tree[idx] += deltaidx += idx & -idxdef query_prefix(self, idx):# Sum from 0-based index 0 to idx (inclusive)res = 0idx += 1 # convert to 1-based indexwhile idx > 0:res += self.tree[idx]idx -= idx & -idxreturn resdef range_query(self, l, r):if l > r:return 0return self.query_prefix(r) - self.query_prefix(l - 1)def main():import sysinput = sys.stdin.read().split()n = int(input[0])s = input[1].strip()agct = [1 if c in {'A', 'G', 'C', 'T'} else 0 for c in s]valid_ft = FenwickTree(n)valid_agct_ft = FenwickTree(n)for i in range(n):valid_ft.update_point(i, 1)if agct[i]:valid_agct_ft.update_point(i, 1)count = 0def find_kth(k):low = 0high = n - 1res = -1while low <= high:mid = (low + high) // 2s = valid_ft.query_prefix(mid)if s >= k:res = midhigh = mid - 1else:low = mid + 1return reswhile True:sum_agct = valid_agct_ft.query_prefix(n - 1)if sum_agct == 0:breakk = sum_agctpos = find_kth(k)if pos == -1:breakvalid_ft.update_point(pos, -1)if agct[pos]:valid_agct_ft.update_point(pos, -1)count += 1print(count)if __name__ == "__main__":main()