結果
問題 | No.705 ゴミ拾い Hard |
ユーザー | 0w1 |
提出日時 | 2018-11-02 20:12:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,511 bytes |
コンパイル時間 | 2,555 ms |
コンパイル使用メモリ | 217,372 KB |
実行使用メモリ | 10,368 KB |
最終ジャッジ日時 | 2024-11-20 14:36:02 |
合計ジャッジ時間 | 9,472 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 2 ms
6,816 KB |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | AC | 2 ms
6,820 KB |
testcase_15 | AC | 2 ms
6,820 KB |
testcase_16 | AC | 3 ms
6,816 KB |
testcase_17 | AC | 2 ms
6,820 KB |
testcase_18 | AC | 2 ms
6,816 KB |
testcase_19 | AC | 2 ms
6,820 KB |
testcase_20 | AC | 2 ms
6,816 KB |
testcase_21 | AC | 2 ms
6,820 KB |
testcase_22 | AC | 2 ms
6,820 KB |
testcase_23 | AC | 3 ms
6,820 KB |
testcase_24 | AC | 173 ms
10,240 KB |
testcase_25 | AC | 172 ms
10,240 KB |
testcase_26 | AC | 173 ms
10,240 KB |
testcase_27 | AC | 173 ms
10,240 KB |
testcase_28 | AC | 174 ms
10,112 KB |
testcase_29 | AC | 172 ms
10,240 KB |
testcase_30 | AC | 175 ms
10,240 KB |
testcase_31 | RE | - |
testcase_32 | AC | 163 ms
10,240 KB |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | AC | 160 ms
10,240 KB |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | AC | 180 ms
10,112 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template<typename R> // return_type struct MongeDP { int n; vector<R> dp; vector<int> pre; function<bool(R, R)> cmp; // true is left better function<R(int, int)> w; MongeDP(int _n, function<bool(R, R)> c, function<R(int, int)> get_cost) : n(_n), dp(n + 1), pre(n + 1, -1), cmp(c), w(get_cost) { deque<tuple<int, int, int>> dcs; // decision dcs.emplace_back(0, 1, n); // transition from dp[0] is effective for [1, N] for (int i = 1; i <= n; ++i) { while (get<2>(dcs.front()) < i) dcs.pop_front(); // right bound is out-dated pre[i] = get<0>(dcs.front()); dp[i] = dp[pre[i]] + w(pre[i], i); // best t is A[dcs.top(), i) while (dcs.size()) { int x, lb, rb; tie(x, lb, rb) = dcs.back(); //if (lb <= i) break; // will be pop_fronted soon anyway if (!cmp(dp[x] + w(x, lb), dp[i] + w(i, lb))) { dcs.pop_back(); if (dcs.size()) get<2>(dcs.back()) = n; } else break; } int best = -1; for (int lb = i + 1, rb = n, x = get<0>(dcs.back()); lb <= rb; ) { int mb = lb + rb >> 1; if (cmp(dp[i] + w(i, mb), dp[x] + w(x, mb))) { best = mb; rb = mb - 1; } else lb = mb + 1; } if (~best) { get<2>(dcs.back()) = best - 1; dcs.emplace_back(i, best, n); } } } void ensure_monge_condition() { // Monge Condition: i <= j <= k <= l then w(i, l) + w(j, k) >(<)= w(i, k) + w(j, l) for (int i = 0; i <= n; ++i) for (int j = i; j <= n; ++j) for (int k = j; k <= n; ++k) for (int l = k; l <= n; ++l) { R w0 = w(i, l), w1 = w(j, k), w2 = w(i, k), w3 = w(j, l); assert(w0 + w1 >= w2 + w3); // if maximization, revert the sign } } R operator[](int x) { return dp[x]; } }; signed main() { ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; ++i) cin >> A[i]; vector<int> X(N); for (int i = 0; i < N; ++i) cin >> X[i]; vector<int> Y(N); for (int i = 0; i < N; ++i) cin >> Y[i]; MongeDP<int64_t> mdp(N, [](int64_t x, int64_t y) { return x < y; }, [&](int x, int rb) { auto abscub = [](int64_t x) { return abs(x * x * x); }; return abscub(A[rb - 1] - X[x]) + abscub(Y[x]); }); // mdp.ensure_monge_condition(); cout << mdp[N] << endl; return 0; }