結果
問題 | No.1008 Bench Craftsman |
ユーザー |
![]() |
提出日時 | 2020-03-06 22:11:21 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,296 bytes |
コンパイル時間 | 151 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 72,268 KB |
最終ジャッジ日時 | 2024-10-14 07:18:03 |
合計ジャッジ時間 | 9,405 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | WA * 2 TLE * 1 -- * 24 |
ソースコード
#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np # %% N, M = map(int, readline().split()) A = np.array(readline().split(), np.int64) m = map(int, read().split()) XW = tuple(zip(m, m)) # %% def test(c): if c == 0: return sum(w for x, w in XW) <= A.min() B1_d = np.zeros(N + 1, np.int64) B0_d = np.zeros(N + 1, np.int64) 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 B1 = B1_d.cumsum()[:-1] B0 = B0_d.cumsum()[:-1] cost = B1 * np.arange(N, dtype=np.int64) + B0 return np.all(cost <= A) # %% if any(A[x - 1] < w for x, w in XW): print(-1) exit() left = -1 right = 10 * 5 + 10 while left + 1 < right: x = (left + right) // 2 if test(x): right = x else: left = x print(right)