結果
問題 | No.1008 Bench Craftsman |
ユーザー | kcvlex |
提出日時 | 2020-03-07 14:07:21 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 141 ms / 2,000 ms |
コード長 | 3,955 bytes |
コンパイル時間 | 1,750 ms |
コンパイル使用メモリ | 174,904 KB |
実行使用メモリ | 11,776 KB |
最終ジャッジ日時 | 2024-10-14 12:45:46 |
合計ジャッジ時間 | 6,116 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
9,344 KB |
testcase_01 | AC | 32 ms
9,472 KB |
testcase_02 | AC | 33 ms
9,344 KB |
testcase_03 | AC | 34 ms
9,344 KB |
testcase_04 | AC | 33 ms
9,472 KB |
testcase_05 | AC | 141 ms
11,776 KB |
testcase_06 | AC | 55 ms
10,464 KB |
testcase_07 | AC | 34 ms
9,472 KB |
testcase_08 | AC | 38 ms
9,472 KB |
testcase_09 | AC | 102 ms
10,880 KB |
testcase_10 | AC | 127 ms
11,648 KB |
testcase_11 | AC | 132 ms
11,776 KB |
testcase_12 | AC | 132 ms
11,776 KB |
testcase_13 | AC | 130 ms
11,700 KB |
testcase_14 | AC | 131 ms
11,776 KB |
testcase_15 | AC | 125 ms
11,776 KB |
testcase_16 | AC | 122 ms
11,776 KB |
testcase_17 | AC | 127 ms
11,648 KB |
testcase_18 | AC | 130 ms
11,776 KB |
testcase_19 | AC | 130 ms
11,776 KB |
testcase_20 | AC | 60 ms
10,296 KB |
testcase_21 | AC | 63 ms
10,240 KB |
testcase_22 | AC | 97 ms
10,876 KB |
testcase_23 | AC | 111 ms
11,136 KB |
testcase_24 | AC | 109 ms
11,136 KB |
testcase_25 | AC | 57 ms
10,296 KB |
testcase_26 | AC | 52 ms
10,112 KB |
testcase_27 | AC | 82 ms
10,496 KB |
testcase_28 | AC | 84 ms
10,752 KB |
testcase_29 | AC | 117 ms
11,264 KB |
ソースコード
#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); }; 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; 0 <= i - 1; 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; }