結果
問題 | No.59 鉄道の旅 |
ユーザー | H3PO4 |
提出日時 | 2020-04-22 22:33:24 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 746 ms / 5,000 ms |
コード長 | 608 bytes |
コンパイル時間 | 452 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 18,560 KB |
最終ジャッジ日時 | 2024-04-20 11:19:08 |
合計ジャッジ時間 | 4,654 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
18,396 KB |
testcase_01 | AC | 44 ms
18,560 KB |
testcase_02 | AC | 44 ms
18,432 KB |
testcase_03 | AC | 45 ms
18,560 KB |
testcase_04 | AC | 677 ms
18,432 KB |
testcase_05 | AC | 46 ms
18,560 KB |
testcase_06 | AC | 47 ms
18,432 KB |
testcase_07 | AC | 47 ms
18,560 KB |
testcase_08 | AC | 118 ms
18,432 KB |
testcase_09 | AC | 114 ms
18,432 KB |
testcase_10 | AC | 116 ms
18,408 KB |
testcase_11 | AC | 88 ms
18,512 KB |
testcase_12 | AC | 397 ms
18,472 KB |
testcase_13 | AC | 732 ms
18,432 KB |
testcase_14 | AC | 746 ms
18,552 KB |
testcase_15 | AC | 47 ms
18,560 KB |
ソースコード
class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N, K = map(int, input().split()) MAX = 1000000 B = Bit(MAX) for _ in range(N): W = int(input()) if W > 0: if B.sum(MAX) - B.sum(W - 1) < K: B.add(W, 1) else: if B.sum(-W) - B.sum(-W - 1): B.add(-W, -1) print(B.sum(MAX))