# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
747877 | 2023-05-25T02:52:36 Z | socho | Discharging (NOI20_discharging) | C++14 | 139 ms | 25640 KB |
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void ran() { srand(chrono::steady_clock::now().time_since_epoch().count()); } long long get_rand() { long long a = rand(); long long b = rand(); return a * (RAND_MAX + 1ll) + b; } void usaco() { freopen("problem.in", "r", stdin); freopen("problem.out", "w", stdout); } template<typename T> using min_pq = priority_queue<T, vector<T>, greater<T>>; // #define endl '\n' // #define double long double #define int long long // const int MOD = 1000 * 1000 * 1000 + 7; // const int MOD = 998244353; int n; const int MXN = 1000005; int t[MXN], dp[MXN]; struct Line { int a, b; Line(int m, int c) { a = m; b = c; } int value(int x) { return a * x + b; } }; // descending hull struct CHT { vector<Line> hull; void addLine(Line c) { while (hull.size() >= 2) { Line a = hull[hull.size()-2]; Line b = hull.back(); // if (xinter(a, b) >= xinter(b, c)) { __int128 l = (b.b - a.b); __int128 m = b.a - c.a; __int128 e = (c.b - b.b); __int128 f = a.a - b.a; if (l * m >= e * f) { hull.pop_back(); } else { break; } } hull.push_back(c); } int query(int x) { int low = 0; int high = hull.size() - 1; while (low < high) { int mid = (low + high) / 2; int v1 = hull[mid].value(x); int v2 = hull[mid+1].value(x); if (v1 < v2) { high = mid; } else { low = mid + 1; } } return hull[low].value(x); } } cht; signed main() { ran(); fast(); cin >> n; for (int i=1; i<=n; i++) { cin >> t[i]; t[i] = max(t[i], t[i-1]); } for (int i=1; i<=n; i++) { dp[i] = t[i] * (i + (n - i)); cht.addLine(Line(-i, dp[i-1])); if (i > 1) dp[i] = min(dp[i], t[i] * (n + 1) + cht.query(t[i])); } cout << dp[n] << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 103 ms | 20896 KB | Output is correct |
17 | Correct | 117 ms | 21908 KB | Output is correct |
18 | Correct | 95 ms | 20284 KB | Output is correct |
19 | Correct | 115 ms | 21692 KB | Output is correct |
20 | Correct | 107 ms | 21560 KB | Output is correct |
21 | Correct | 110 ms | 21728 KB | Output is correct |
22 | Correct | 112 ms | 21248 KB | Output is correct |
23 | Correct | 120 ms | 22324 KB | Output is correct |
24 | Correct | 115 ms | 21824 KB | Output is correct |
25 | Correct | 116 ms | 22152 KB | Output is correct |
26 | Correct | 117 ms | 22504 KB | Output is correct |
27 | Correct | 101 ms | 21004 KB | Output is correct |
28 | Correct | 109 ms | 21844 KB | Output is correct |
29 | Correct | 119 ms | 21984 KB | Output is correct |
30 | Correct | 119 ms | 22236 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 119 ms | 25512 KB | Output is correct |
2 | Correct | 117 ms | 25584 KB | Output is correct |
3 | Correct | 116 ms | 25640 KB | Output is correct |
4 | Correct | 115 ms | 25584 KB | Output is correct |
5 | Correct | 113 ms | 25628 KB | Output is correct |
6 | Correct | 114 ms | 25580 KB | Output is correct |
7 | Correct | 121 ms | 25588 KB | Output is correct |
8 | Correct | 122 ms | 25636 KB | Output is correct |
9 | Correct | 139 ms | 25556 KB | Output is correct |
10 | Correct | 118 ms | 25572 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 340 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 1 ms | 340 KB | Output is correct |
28 | Correct | 1 ms | 340 KB | Output is correct |
29 | Correct | 1 ms | 336 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 332 KB | Output is correct |
33 | Correct | 1 ms | 340 KB | Output is correct |
34 | Correct | 1 ms | 340 KB | Output is correct |
35 | Correct | 1 ms | 340 KB | Output is correct |
36 | Correct | 1 ms | 260 KB | Output is correct |
37 | Correct | 1 ms | 340 KB | Output is correct |
38 | Correct | 1 ms | 340 KB | Output is correct |
39 | Correct | 1 ms | 336 KB | Output is correct |
40 | Correct | 1 ms | 340 KB | Output is correct |
41 | Correct | 1 ms | 340 KB | Output is correct |
42 | Correct | 1 ms | 340 KB | Output is correct |
43 | Correct | 1 ms | 340 KB | Output is correct |
44 | Correct | 1 ms | 340 KB | Output is correct |
45 | Correct | 1 ms | 336 KB | Output is correct |
46 | Correct | 1 ms | 340 KB | Output is correct |
47 | Correct | 1 ms | 340 KB | Output is correct |
48 | Correct | 1 ms | 340 KB | Output is correct |
49 | Correct | 1 ms | 340 KB | Output is correct |
50 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 340 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 1 ms | 340 KB | Output is correct |
28 | Correct | 1 ms | 340 KB | Output is correct |
29 | Correct | 1 ms | 336 KB | Output is correct |
30 | Correct | 103 ms | 20896 KB | Output is correct |
31 | Correct | 117 ms | 21908 KB | Output is correct |
32 | Correct | 95 ms | 20284 KB | Output is correct |
33 | Correct | 115 ms | 21692 KB | Output is correct |
34 | Correct | 107 ms | 21560 KB | Output is correct |
35 | Correct | 110 ms | 21728 KB | Output is correct |
36 | Correct | 112 ms | 21248 KB | Output is correct |
37 | Correct | 120 ms | 22324 KB | Output is correct |
38 | Correct | 115 ms | 21824 KB | Output is correct |
39 | Correct | 116 ms | 22152 KB | Output is correct |
40 | Correct | 117 ms | 22504 KB | Output is correct |
41 | Correct | 101 ms | 21004 KB | Output is correct |
42 | Correct | 109 ms | 21844 KB | Output is correct |
43 | Correct | 119 ms | 21984 KB | Output is correct |
44 | Correct | 119 ms | 22236 KB | Output is correct |
45 | Correct | 119 ms | 25512 KB | Output is correct |
46 | Correct | 117 ms | 25584 KB | Output is correct |
47 | Correct | 116 ms | 25640 KB | Output is correct |
48 | Correct | 115 ms | 25584 KB | Output is correct |
49 | Correct | 113 ms | 25628 KB | Output is correct |
50 | Correct | 114 ms | 25580 KB | Output is correct |
51 | Correct | 121 ms | 25588 KB | Output is correct |
52 | Correct | 122 ms | 25636 KB | Output is correct |
53 | Correct | 139 ms | 25556 KB | Output is correct |
54 | Correct | 118 ms | 25572 KB | Output is correct |
55 | Correct | 1 ms | 340 KB | Output is correct |
56 | Correct | 1 ms | 340 KB | Output is correct |
57 | Correct | 1 ms | 332 KB | Output is correct |
58 | Correct | 1 ms | 340 KB | Output is correct |
59 | Correct | 1 ms | 340 KB | Output is correct |
60 | Correct | 1 ms | 340 KB | Output is correct |
61 | Correct | 1 ms | 260 KB | Output is correct |
62 | Correct | 1 ms | 340 KB | Output is correct |
63 | Correct | 1 ms | 340 KB | Output is correct |
64 | Correct | 1 ms | 336 KB | Output is correct |
65 | Correct | 1 ms | 340 KB | Output is correct |
66 | Correct | 1 ms | 340 KB | Output is correct |
67 | Correct | 1 ms | 340 KB | Output is correct |
68 | Correct | 1 ms | 340 KB | Output is correct |
69 | Correct | 1 ms | 340 KB | Output is correct |
70 | Correct | 1 ms | 336 KB | Output is correct |
71 | Correct | 1 ms | 340 KB | Output is correct |
72 | Correct | 1 ms | 340 KB | Output is correct |
73 | Correct | 1 ms | 340 KB | Output is correct |
74 | Correct | 1 ms | 340 KB | Output is correct |
75 | Correct | 1 ms | 340 KB | Output is correct |
76 | Correct | 105 ms | 21984 KB | Output is correct |
77 | Correct | 101 ms | 22008 KB | Output is correct |
78 | Correct | 94 ms | 21364 KB | Output is correct |
79 | Correct | 99 ms | 21608 KB | Output is correct |
80 | Correct | 110 ms | 22192 KB | Output is correct |
81 | Correct | 100 ms | 21492 KB | Output is correct |
82 | Correct | 98 ms | 21384 KB | Output is correct |
83 | Correct | 100 ms | 21924 KB | Output is correct |
84 | Correct | 96 ms | 21708 KB | Output is correct |
85 | Correct | 102 ms | 21960 KB | Output is correct |
86 | Correct | 99 ms | 21324 KB | Output is correct |
87 | Correct | 96 ms | 21276 KB | Output is correct |
88 | Correct | 98 ms | 21596 KB | Output is correct |
89 | Correct | 98 ms | 21504 KB | Output is correct |
90 | Correct | 94 ms | 21352 KB | Output is correct |
91 | Correct | 108 ms | 21208 KB | Output is correct |
92 | Correct | 119 ms | 22436 KB | Output is correct |
93 | Correct | 113 ms | 21720 KB | Output is correct |
94 | Correct | 109 ms | 20832 KB | Output is correct |
95 | Correct | 105 ms | 22256 KB | Output is correct |
96 | Correct | 93 ms | 21196 KB | Output is correct |
97 | Correct | 93 ms | 21452 KB | Output is correct |
98 | Correct | 101 ms | 21688 KB | Output is correct |
99 | Correct | 97 ms | 21324 KB | Output is correct |
100 | Correct | 101 ms | 21384 KB | Output is correct |