結果
問題 | No.1008 Bench Craftsman |
ユーザー | kcvlex |
提出日時 | 2020-03-07 13:44:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,961 bytes |
コンパイル時間 | 1,546 ms |
コンパイル使用メモリ | 174,056 KB |
実行使用メモリ | 11,904 KB |
最終ジャッジ日時 | 2024-10-14 12:30:53 |
合計ジャッジ時間 | 5,185 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
9,344 KB |
testcase_01 | AC | 27 ms
9,552 KB |
testcase_02 | AC | 29 ms
9,600 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 46 ms
10,416 KB |
testcase_07 | AC | 28 ms
9,472 KB |
testcase_08 | AC | 32 ms
9,472 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 51 ms
10,240 KB |
testcase_26 | AC | 45 ms
10,112 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
ソースコード
#include <bits/stdc++.h> #define ALL(v) std::begin(v), std::end(v) #define ALLR(v) std::rbegin(v), std::rend(v) using ll = std::int64_t; using ull = std::uint64_t; using pll = std::pair<ll, ll>; using tll = std::tuple<ll, ll, ll>; template <typename T> using vec = std::vector<T>; template <typename T> using vvec = vec<vec<T>>; template <typename T> const T& var_min(const T &t) { return t; } template <typename T> const T& var_max(const T &t) { return t; } template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); } template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); } namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } #define mv_rec make_v(init, tail...) template <typename T> T make_v(T init) { return init; } template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return vec<decltype(mv_rec)>(s, mv_rec); } #undef mv_rec namespace ios { char line = '\n'; } template <typename T> std::ostream& operator <<(std::ostream &os, const vec<T> &v) { for (ll i = 0; i < v.size(); i++) os << v[i] << " \n"[i + 1 == v.size()]; return os; } struct Solver { ll n, m; vec<ll> av; vec<pll> xw; vec<ll> imos1, imos2; constexpr static std::size_t SIZE = 2e5 + 10; Solver(ll n, ll m) : n(n), m(m), av(n), xw(m), imos1(2 * SIZE), imos2(2 * SIZE) { for (auto &&e : av) std::cin >> e; for (auto &&e : xw) { ll x, w; std::cin >> x >> w; e = pll(x - 1, w); } } bool check(ll c) { fill(ALL(imos1), 0); fill(ALL(imos2), 0); auto calc_len = [&](ll w) { return (c == 0 ? n + 5 : w / c + !!(w % c)); }; for (ll j = 0; j < m; j++) { ll x, w; std::tie(x, w) = xw[j]; ll len = calc_len(w); imos1[x + 1] -= c; imos1[x + 1 + len] += c; imos2[x - 1 + SIZE] -= c; imos2[x - 1 - len + SIZE] += c; } auto fold_imos = [&] { for (ll i = 0; i + 1 < imos1.size(); i++) imos1[i + 1] += imos1[i]; for (ll i = imos2.size() - 1; 1 <= i; i--) imos2[i - 1] += imos2[i]; }; fold_imos(); for (ll j = 0; j < m; j++) { ll x, w; std::tie(x, w) = xw[j]; ll len = calc_len(w); ll sumv = c * len; imos1[x] += w; imos1[x + 1 + len] -= w + sumv; imos2[x + SIZE] += w; imos2[x - 1 - len + SIZE] -= w + sumv; } fold_imos(); for (ll j = 0; j < m; j++) { ll x, w; std::tie(x, w) = xw[j]; imos2[x + SIZE] -= w; } for (ll i = 0; i < n; i++) { ll a = av[i]; a -= imos1[i]; a -= imos2[i + SIZE]; if (a <= 0) return false; } return true; } ll solve() { ll init = 1e5 + 10; ll ok = init, ng = -1; while (ok - ng > 1) { ll mid = (ok + ng) / 2; (check(mid) ? ok : ng) = mid; } return (ok == init ? -1 : ok); } }; int main() { ll n, m; std::cin >> n >> m; Solver solver(n, m); std::cout << solver.solve() << ios::line; return 0; }