結果
問題 | No.1012 荷物収集 |
ユーザー | はむ吉🐹 |
提出日時 | 2020-03-20 22:51:36 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 791 ms / 2,000 ms |
コード長 | 1,224 bytes |
コンパイル時間 | 110 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 41,376 KB |
最終ジャッジ日時 | 2024-12-15 07:38:06 |
合計ジャッジ時間 | 18,328 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
11,008 KB |
testcase_01 | AC | 31 ms
11,008 KB |
testcase_02 | AC | 31 ms
10,880 KB |
testcase_03 | AC | 30 ms
10,880 KB |
testcase_04 | AC | 609 ms
41,372 KB |
testcase_05 | AC | 583 ms
41,364 KB |
testcase_06 | AC | 580 ms
41,240 KB |
testcase_07 | AC | 583 ms
41,240 KB |
testcase_08 | AC | 587 ms
41,244 KB |
testcase_09 | AC | 597 ms
41,244 KB |
testcase_10 | AC | 586 ms
41,240 KB |
testcase_11 | AC | 617 ms
41,376 KB |
testcase_12 | AC | 585 ms
41,240 KB |
testcase_13 | AC | 605 ms
41,244 KB |
testcase_14 | AC | 31 ms
11,008 KB |
testcase_15 | AC | 32 ms
10,880 KB |
testcase_16 | AC | 31 ms
10,880 KB |
testcase_17 | AC | 32 ms
10,880 KB |
testcase_18 | AC | 33 ms
10,880 KB |
testcase_19 | AC | 31 ms
11,008 KB |
testcase_20 | AC | 31 ms
10,880 KB |
testcase_21 | AC | 31 ms
10,880 KB |
testcase_22 | AC | 31 ms
11,008 KB |
testcase_23 | AC | 30 ms
10,880 KB |
testcase_24 | AC | 489 ms
27,432 KB |
testcase_25 | AC | 680 ms
35,020 KB |
testcase_26 | AC | 428 ms
30,484 KB |
testcase_27 | AC | 110 ms
15,744 KB |
testcase_28 | AC | 699 ms
37,304 KB |
testcase_29 | AC | 485 ms
36,504 KB |
testcase_30 | AC | 763 ms
40,240 KB |
testcase_31 | AC | 196 ms
18,284 KB |
testcase_32 | AC | 222 ms
17,896 KB |
testcase_33 | AC | 297 ms
19,712 KB |
testcase_34 | AC | 298 ms
20,840 KB |
testcase_35 | AC | 582 ms
34,764 KB |
testcase_36 | AC | 244 ms
20,272 KB |
testcase_37 | AC | 474 ms
34,632 KB |
testcase_38 | AC | 518 ms
29,372 KB |
testcase_39 | AC | 250 ms
21,372 KB |
testcase_40 | AC | 280 ms
20,616 KB |
testcase_41 | AC | 791 ms
38,920 KB |
testcase_42 | AC | 341 ms
22,652 KB |
testcase_43 | AC | 509 ms
31,304 KB |
testcase_44 | AC | 31 ms
11,008 KB |
ソースコード
#!/usr/bin/env python3 import bisect import itertools class CumulativeSum(object): def __init__(self, sequence): self.cumulative_sum = [0] self.cumulative_sum.extend(itertools.accumulate(sequence)) def partial_sum(self, first, last): return self.cumulative_sum[last + 1] - self.cumulative_sum[first] def process_queries(xs0, ws0, ys): pairs = sorted(zip(xs0, ws0)) xs = [x for x, _ in pairs] ws = [w for _, w in pairs] n = len(xs) w_cs = CumulativeSum(ws) xw_cs = CumulativeSum(x * w for x, w in zip(xs, ws)) for y in ys: pos = bisect.bisect(xs, y) left_sum = y * w_cs.partial_sum(0, pos - 1) - \ xw_cs.partial_sum(0, pos - 1) right_sum = xw_cs.partial_sum( pos, n - 1) - y * w_cs.partial_sum(pos, n - 1) all_sum = left_sum + right_sum yield all_sum def main(): n, q = (int(z) for z in input().split()) xs = [] ws = [] for _ in range(n): x, w = (int(z) for z in input().split()) xs.append(x) ws.append(w) ys = [int(z) for z in input().split()] for res in process_queries(xs, ws, ys): print(res) if __name__ == "__main__": main()