結果
問題 | No.1008 Bench Craftsman |
ユーザー | 👑 emthrm |
提出日時 | 2020-03-06 22:25:22 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 696 ms / 2,000 ms |
コード長 | 3,313 bytes |
コンパイル時間 | 2,349 ms |
コンパイル使用メモリ | 210,960 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-10-14 08:03:09 |
合計ジャッジ時間 | 13,233 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 696 ms
11,520 KB |
testcase_06 | AC | 231 ms
10,624 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 3 ms
5,248 KB |
testcase_09 | AC | 94 ms
5,248 KB |
testcase_10 | AC | 654 ms
11,392 KB |
testcase_11 | AC | 650 ms
11,520 KB |
testcase_12 | AC | 655 ms
11,520 KB |
testcase_13 | AC | 617 ms
11,520 KB |
testcase_14 | AC | 637 ms
11,392 KB |
testcase_15 | AC | 28 ms
5,248 KB |
testcase_16 | AC | 638 ms
11,520 KB |
testcase_17 | AC | 30 ms
5,248 KB |
testcase_18 | AC | 588 ms
11,520 KB |
testcase_19 | AC | 626 ms
11,392 KB |
testcase_20 | AC | 214 ms
7,808 KB |
testcase_21 | AC | 228 ms
6,928 KB |
testcase_22 | AC | 327 ms
5,912 KB |
testcase_23 | AC | 455 ms
8,668 KB |
testcase_24 | AC | 463 ms
7,424 KB |
testcase_25 | AC | 203 ms
9,508 KB |
testcase_26 | AC | 156 ms
7,976 KB |
testcase_27 | AC | 265 ms
5,248 KB |
testcase_28 | AC | 358 ms
8,988 KB |
testcase_29 | AC | 540 ms
10,036 KB |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); } } iosetup; template <typename Abelian> struct BITRangeAdd { BITRangeAdd(int n_, const Abelian UNITY = 0) : n(n_), UNITY(UNITY) { ++n; dat_const.assign(n, UNITY); dat_linear.assign(n, UNITY); } void add(int left, int right, Abelian val) { if (right < ++left) return; for (int i = left; i < n; i += i & -i) { dat_const[i] -= val * (left - 1); dat_linear[i] += val; } for (int i = right + 1; i < n; i += i & -i) { dat_const[i] += val * right; dat_linear[i] -= val; } } Abelian sum(int idx) { Abelian res = UNITY; for (int i = idx; i > 0; i -= i & -i) res += dat_linear[i]; res *= idx; for (int i = idx; i > 0; i -= i & -i) res += dat_const[i]; return res; } Abelian sum(int left, int right) { if (right <= left) return UNITY; return sum(right) - sum(left); } Abelian operator[](const int idx) { return sum(idx, idx + 1); } private: int n; const Abelian UNITY; vector<Abelian> dat_const, dat_linear; }; int main() { int n, m; cin >> n >> m; vector<int> a(n); REP(i, n) cin >> a[i]; vector<int> x(m), w(m); REP(i, m) cin >> x[i] >> w[i], --x[i]; vector<ll> bench(n, 0); REP(i, m) bench[x[i]] += w[i]; REP(i, n) { if (bench[i] >= a[i]) { cout << "-1\n"; return 0; } } if (*min_element(ALL(a)) > accumulate(ALL(w), 0LL)) { cout << "0\n"; return 0; } ll lb = 0, ub = 100000; while (ub - lb > 1) { ll mid = (lb + ub) >> 1; BITRangeAdd<ll> ci(n), left(n), right(n); REP(i, m) { int ran = w[i] / mid; int l = min(x[i], ran), r = min(n - 1 - x[i], ran); ci.add(x[i] - l, x[i] + r + 1, w[i]); left.add(x[i] - l, x[i], -1); if (x[i] - l > 0) left.add(x[i] - l - 1, x[i] - l, l); right.add(x[i] + 1, x[i] + r + 1, -1); if (x[i] + r + 1 < n) right.add(x[i] + r + 1, x[i] + r + 2, r); } vector<ll> L(n), R(n); REP(i, n) L[i] = left[i]; for (int i = n - 2; i >= 0; --i) L[i] += L[i + 1]; REP(i, n) R[i] = right[i]; FOR(i, 1, n) R[i] += R[i - 1]; bool ok = true; // cout << mid << ":\n"; // REP(i, n) cout << ci[i] << " \n"[i + 1 == n]; // REP(i, n) cout << L[i] << " \n"[i + 1 == n]; // REP(i, n) cout << R[i] << " \n"[i + 1 == n]; REP(i, n) { ll load = ci[i] + (L[i] + R[i]) * mid; // cout << load << " \n"[i + 1 == n]; ok &= load < a[i]; } (ok ? ub : lb) = mid; } cout << ub << '\n'; return 0; }