結果
問題 | No.704 ゴミ拾い Medium |
ユーザー | goodbaton |
提出日時 | 2019-10-29 01:49:43 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 479 ms / 1,500 ms |
コード長 | 3,289 bytes |
コンパイル時間 | 1,472 ms |
コンパイル使用メモリ | 119,804 KB |
実行使用メモリ | 26,652 KB |
最終ジャッジ日時 | 2024-09-14 21:22:20 |
合計ジャッジ時間 | 11,326 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
7,632 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,948 KB |
testcase_03 | AC | 2 ms
7,884 KB |
testcase_04 | AC | 3 ms
7,636 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 3 ms
7,760 KB |
testcase_07 | AC | 3 ms
7,888 KB |
testcase_08 | AC | 3 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 3 ms
7,756 KB |
testcase_13 | AC | 2 ms
7,636 KB |
testcase_14 | AC | 4 ms
6,948 KB |
testcase_15 | AC | 4 ms
7,760 KB |
testcase_16 | AC | 4 ms
7,884 KB |
testcase_17 | AC | 4 ms
6,944 KB |
testcase_18 | AC | 4 ms
7,896 KB |
testcase_19 | AC | 4 ms
7,888 KB |
testcase_20 | AC | 4 ms
7,760 KB |
testcase_21 | AC | 4 ms
7,888 KB |
testcase_22 | AC | 4 ms
6,940 KB |
testcase_23 | AC | 4 ms
7,888 KB |
testcase_24 | AC | 468 ms
26,168 KB |
testcase_25 | AC | 466 ms
25,660 KB |
testcase_26 | AC | 473 ms
26,536 KB |
testcase_27 | AC | 462 ms
25,280 KB |
testcase_28 | AC | 460 ms
26,652 KB |
testcase_29 | AC | 474 ms
26,400 KB |
testcase_30 | AC | 465 ms
25,428 KB |
testcase_31 | AC | 464 ms
25,940 KB |
testcase_32 | AC | 466 ms
26,332 KB |
testcase_33 | AC | 479 ms
26,628 KB |
testcase_34 | AC | 123 ms
15,676 KB |
testcase_35 | AC | 123 ms
17,124 KB |
testcase_36 | AC | 124 ms
16,636 KB |
testcase_37 | AC | 123 ms
18,352 KB |
testcase_38 | AC | 124 ms
17,824 KB |
testcase_39 | AC | 124 ms
16,680 KB |
testcase_40 | AC | 125 ms
16,448 KB |
testcase_41 | AC | 125 ms
16,396 KB |
testcase_42 | AC | 124 ms
16,604 KB |
testcase_43 | AC | 122 ms
16,312 KB |
testcase_44 | AC | 3 ms
7,764 KB |
testcase_45 | AC | 3 ms
6,940 KB |
testcase_46 | AC | 131 ms
16,020 KB |
testcase_47 | AC | 135 ms
16,908 KB |
ソースコード
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <iostream> #include <complex> #include <string> #include <algorithm> #include <numeric> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <functional> #include <cassert> typedef long long ll; using namespace std; #ifndef LOCAL #define debug(x) ; #else #define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl; template <typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &p) { out << "{" << p.first << ", " << p.second << "}"; return out; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) { out << '{'; for (const T &item : v) out << item << ", "; out << "\b\b}"; return out; } #endif #define mod 1000000007 //1e9+7(prime number) #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define SIZE 300010 template<typename T> struct LiChaoTree { using Line = pair<T, T>; // first * x + second int segn2; vector<Line> data; vector<T> X; template<typename S> LiChaoTree(vector<S> pos) { int N = pos.size(); for (segn2 = 1; segn2 < N; segn2 *= 2); data.assign(segn2 * 2, {0, INF}); X.assign(segn2, INF); for (int i=0; i<pos.size(); i++) X[i] = pos[i]; } inline T f(Line line, T x) { return line.first * x + line.second; } void addLine(int a, int b, Line line, int l = 0, int r = -1, int k = 0) { if (r == -1) r = segn2; int m = (l + r) / 2; if (r <= a || b <= l) return; if (l < a || b < r) { addLine(a, b, line, l, m, k*2+1); addLine(a, b, line, m, r, k*2+2); return; } if (data[k].second == INF) { //isNull data[k] = line; return; } bool fl = f(line, X[l]) < f(data[k], X[l]); bool fm = f(line, X[m]) < f(data[k], X[m]); bool fr = f(line, X[r-1]) < f(data[k], X[r-1]); if (fl == fr) { if (fl) data[k] = line; return; } if (fm) swap(data[k], line); if (fl ^ fm) addLine(a, b, line, l, m, 2*k+1); else addLine(a, b, line, m, r, 2*k+2); } void addLine(Line line) { addLine(0, segn2, line); } T query(int k) { T x = X[k], res = LLINF; k += segn2-1; while(1){ if (data[k].second != INF) //isNotNull res = min(res, f(data[k], x)); if (!k) break; k = (k - 1) / 2; } return res; } }; int main(){ int N, A[SIZE], X[SIZE], Y[SIZE]; ll dp[SIZE]; scanf("%d", &N); for (int i=0; i<N; i++) scanf("%d", A+i); for (int i=0; i<N; i++) scanf("%d", X+i); for (int i=0; i<N; i++) scanf("%d", Y+i); vector<ll> vec; map<ll, int> dic; for (int i=0; i<N; i++) vec.push_back(X[i]); for (int i=0; i<N; i++) vec.push_back(A[i]); sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); debug(vec); LiChaoTree<ll> tree(vec); for (int i=0; i<vec.size(); i++) dic[vec[i]] = i; dp[0] = 0; for (int i=0; i<N; i++) { tree.addLine(0, dic[X[i]], {-1, Y[i] + dp[i] + X[i]}); tree.addLine(dic[X[i]], vec.size(), {1, Y[i] + dp[i] - X[i]}); dp[i+1] = tree.query(dic[A[i]]); debug(dp[i+1]); } cout << dp[N] << endl; return 0; }