結果
問題 | No.59 鉄道の旅 |
ユーザー | H3PO4 |
提出日時 | 2020-04-22 22:33:24 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
AC
|
実行時間 | 585 ms / 5,000 ms |
コード長 | 608 bytes |
コンパイル時間 | 378 ms |
コンパイル使用メモリ | 10,892 KB |
実行使用メモリ | 16,096 KB |
最終ジャッジ日時 | 2023-08-02 11:54:06 |
合計ジャッジ時間 | 4,279 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
15,684 KB |
testcase_01 | AC | 30 ms
15,844 KB |
testcase_02 | AC | 32 ms
15,832 KB |
testcase_03 | AC | 33 ms
15,924 KB |
testcase_04 | AC | 567 ms
15,900 KB |
testcase_05 | AC | 33 ms
15,904 KB |
testcase_06 | AC | 35 ms
15,744 KB |
testcase_07 | AC | 34 ms
15,872 KB |
testcase_08 | AC | 93 ms
15,908 KB |
testcase_09 | AC | 89 ms
16,096 KB |
testcase_10 | AC | 91 ms
15,936 KB |
testcase_11 | AC | 66 ms
15,880 KB |
testcase_12 | AC | 329 ms
15,988 KB |
testcase_13 | AC | 570 ms
15,940 KB |
testcase_14 | AC | 585 ms
16,096 KB |
testcase_15 | AC | 30 ms
15,688 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))