結果
問題 | No.1008 Bench Craftsman |
ユーザー | maspy |
提出日時 | 2020-03-06 22:39:07 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 411 ms / 2,000 ms |
コード長 | 1,396 bytes |
コンパイル時間 | 1,541 ms |
コンパイル使用メモリ | 86,724 KB |
実行使用メモリ | 179,740 KB |
最終ジャッジ日時 | 2023-08-04 12:10:37 |
合計ジャッジ時間 | 10,699 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
71,444 KB |
testcase_01 | AC | 69 ms
71,424 KB |
testcase_02 | AC | 68 ms
71,436 KB |
testcase_03 | AC | 66 ms
71,468 KB |
testcase_04 | AC | 70 ms
71,304 KB |
testcase_05 | AC | 411 ms
174,680 KB |
testcase_06 | AC | 269 ms
161,592 KB |
testcase_07 | AC | 70 ms
71,456 KB |
testcase_08 | AC | 89 ms
76,748 KB |
testcase_09 | AC | 210 ms
102,076 KB |
testcase_10 | AC | 367 ms
158,632 KB |
testcase_11 | AC | 373 ms
159,552 KB |
testcase_12 | AC | 388 ms
168,324 KB |
testcase_13 | AC | 388 ms
177,688 KB |
testcase_14 | AC | 377 ms
169,520 KB |
testcase_15 | AC | 373 ms
179,740 KB |
testcase_16 | AC | 367 ms
166,716 KB |
testcase_17 | AC | 372 ms
176,992 KB |
testcase_18 | AC | 383 ms
161,536 KB |
testcase_19 | AC | 379 ms
171,972 KB |
testcase_20 | AC | 225 ms
131,020 KB |
testcase_21 | AC | 204 ms
118,108 KB |
testcase_22 | AC | 221 ms
100,880 KB |
testcase_23 | AC | 300 ms
136,136 KB |
testcase_24 | AC | 276 ms
125,724 KB |
testcase_25 | AC | 261 ms
144,960 KB |
testcase_26 | AC | 224 ms
131,256 KB |
testcase_27 | AC | 190 ms
95,456 KB |
testcase_28 | AC | 282 ms
137,972 KB |
testcase_29 | AC | 349 ms
152,192 KB |
ソースコード
#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools # %% N, M = map(int, readline().split()) A = list(map(int, readline().split())) m = map(int, read().split()) XW = tuple(zip(m, m)) # %% def calc_cost(N, c, XW): B1_d = [0] * (N + 1) B0_d = [0] * (N + 1) for x, w in XW: x -= 1 L = x - (w + c - 1) // c + 1 if L < 0: L = 0 const_term = w - c * x B1_d[L] += c B0_d[L] += const_term B1_d[x + 1] -= c B0_d[x + 1] -= const_term R = x + (w + c - 1) // c - 1 const_term = w + c * x if R >= N: R = N - 1 B1_d[x + 1] -= c B0_d[x + 1] += const_term B1_d[R + 1] += c B0_d[R + 1] -= const_term B0 = list(itertools.accumulate(B0_d))[:-1] B1 = list(itertools.accumulate(B1_d))[:-1] cost = [a * i + b for i, (a, b) in enumerate(zip(B1, B0))] return cost def test(c): if c == 0: return sum(w for x, w in XW) <= min(A) cost = calc_cost(N, c, XW) return all(x < a for a, x in zip(A, cost)) # %% left = -1 right = 10 ** 5 + 10 while left + 1 < right: mid = (left + right) // 2 if test(mid): right = mid else: left = mid if right > 10 ** 5: print(-1) else: print(right)