# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
284225 |
2020-08-27T04:11:38 Z |
김동현(#5767) |
Discharging (NOI20_discharging) |
C++17 |
|
156 ms |
22520 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;
#define x first
#define y second
#define all(v) v.begin(),v.end()
namespace Cht {
struct Lin {
ll a, b;
ll f(ll x){ return a * x + b; }
};
deque<Lin> dq;
int sz;
int pop(Lin p, Lin q, Lin r) {
return __int128_t(r.b - p.b) * (p.a - q.a) < __int128_t(q.b - p.b) * (p.a - r.a);
}
void u(ll a, ll b){
Lin cur = {a, b};
while(sz >= 2 && pop(dq[sz - 2], dq[sz - 1], cur)){ dq.pop_back(); sz--; }
dq.push_back(cur); sz++;
}
ll g(ll x) {
while(sz >= 2 && dq[0].f(x) > dq[1].f(x)){ dq.pop_front(); sz--; }
return dq[0].f(x);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vll a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
a[i] = max(a[i], a[i - 1]);
}
vll d(n + 1);
Cht::u(n, 0);
for(int i = 1; i <= n; i++){
d[i] = Cht::g(a[i]);
Cht::u(n - i, d[i]);
}
cout << d[n] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
113 ms |
16888 KB |
Output is correct |
17 |
Correct |
121 ms |
16632 KB |
Output is correct |
18 |
Correct |
113 ms |
16632 KB |
Output is correct |
19 |
Correct |
132 ms |
16632 KB |
Output is correct |
20 |
Correct |
127 ms |
16632 KB |
Output is correct |
21 |
Correct |
118 ms |
16632 KB |
Output is correct |
22 |
Correct |
116 ms |
16668 KB |
Output is correct |
23 |
Correct |
156 ms |
16632 KB |
Output is correct |
24 |
Correct |
121 ms |
16632 KB |
Output is correct |
25 |
Correct |
146 ms |
16632 KB |
Output is correct |
26 |
Correct |
129 ms |
16632 KB |
Output is correct |
27 |
Correct |
113 ms |
16632 KB |
Output is correct |
28 |
Correct |
121 ms |
16632 KB |
Output is correct |
29 |
Correct |
125 ms |
16632 KB |
Output is correct |
30 |
Correct |
126 ms |
16632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
16808 KB |
Output is correct |
2 |
Correct |
141 ms |
16760 KB |
Output is correct |
3 |
Correct |
134 ms |
16632 KB |
Output is correct |
4 |
Correct |
143 ms |
16632 KB |
Output is correct |
5 |
Correct |
136 ms |
16632 KB |
Output is correct |
6 |
Correct |
135 ms |
16632 KB |
Output is correct |
7 |
Correct |
135 ms |
16672 KB |
Output is correct |
8 |
Correct |
133 ms |
16632 KB |
Output is correct |
9 |
Correct |
140 ms |
16504 KB |
Output is correct |
10 |
Correct |
140 ms |
16508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
1 ms |
400 KB |
Output is correct |
41 |
Correct |
1 ms |
384 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
1 ms |
396 KB |
Output is correct |
45 |
Correct |
1 ms |
384 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
1 ms |
384 KB |
Output is correct |
50 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
113 ms |
16888 KB |
Output is correct |
31 |
Correct |
121 ms |
16632 KB |
Output is correct |
32 |
Correct |
113 ms |
16632 KB |
Output is correct |
33 |
Correct |
132 ms |
16632 KB |
Output is correct |
34 |
Correct |
127 ms |
16632 KB |
Output is correct |
35 |
Correct |
118 ms |
16632 KB |
Output is correct |
36 |
Correct |
116 ms |
16668 KB |
Output is correct |
37 |
Correct |
156 ms |
16632 KB |
Output is correct |
38 |
Correct |
121 ms |
16632 KB |
Output is correct |
39 |
Correct |
146 ms |
16632 KB |
Output is correct |
40 |
Correct |
129 ms |
16632 KB |
Output is correct |
41 |
Correct |
113 ms |
16632 KB |
Output is correct |
42 |
Correct |
121 ms |
16632 KB |
Output is correct |
43 |
Correct |
125 ms |
16632 KB |
Output is correct |
44 |
Correct |
126 ms |
16632 KB |
Output is correct |
45 |
Correct |
133 ms |
16808 KB |
Output is correct |
46 |
Correct |
141 ms |
16760 KB |
Output is correct |
47 |
Correct |
134 ms |
16632 KB |
Output is correct |
48 |
Correct |
143 ms |
16632 KB |
Output is correct |
49 |
Correct |
136 ms |
16632 KB |
Output is correct |
50 |
Correct |
135 ms |
16632 KB |
Output is correct |
51 |
Correct |
135 ms |
16672 KB |
Output is correct |
52 |
Correct |
133 ms |
16632 KB |
Output is correct |
53 |
Correct |
140 ms |
16504 KB |
Output is correct |
54 |
Correct |
140 ms |
16508 KB |
Output is correct |
55 |
Correct |
1 ms |
384 KB |
Output is correct |
56 |
Correct |
1 ms |
384 KB |
Output is correct |
57 |
Correct |
1 ms |
384 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
1 ms |
384 KB |
Output is correct |
62 |
Correct |
1 ms |
384 KB |
Output is correct |
63 |
Correct |
1 ms |
384 KB |
Output is correct |
64 |
Correct |
1 ms |
384 KB |
Output is correct |
65 |
Correct |
1 ms |
400 KB |
Output is correct |
66 |
Correct |
1 ms |
384 KB |
Output is correct |
67 |
Correct |
1 ms |
384 KB |
Output is correct |
68 |
Correct |
1 ms |
384 KB |
Output is correct |
69 |
Correct |
1 ms |
396 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
1 ms |
384 KB |
Output is correct |
72 |
Correct |
1 ms |
384 KB |
Output is correct |
73 |
Correct |
1 ms |
384 KB |
Output is correct |
74 |
Correct |
1 ms |
384 KB |
Output is correct |
75 |
Correct |
1 ms |
384 KB |
Output is correct |
76 |
Correct |
118 ms |
16652 KB |
Output is correct |
77 |
Correct |
128 ms |
16752 KB |
Output is correct |
78 |
Correct |
116 ms |
21496 KB |
Output is correct |
79 |
Correct |
116 ms |
21856 KB |
Output is correct |
80 |
Correct |
120 ms |
22392 KB |
Output is correct |
81 |
Correct |
139 ms |
21624 KB |
Output is correct |
82 |
Correct |
134 ms |
21496 KB |
Output is correct |
83 |
Correct |
145 ms |
22008 KB |
Output is correct |
84 |
Correct |
119 ms |
21880 KB |
Output is correct |
85 |
Correct |
120 ms |
22084 KB |
Output is correct |
86 |
Correct |
113 ms |
21496 KB |
Output is correct |
87 |
Correct |
113 ms |
21408 KB |
Output is correct |
88 |
Correct |
119 ms |
21880 KB |
Output is correct |
89 |
Correct |
119 ms |
21496 KB |
Output is correct |
90 |
Correct |
117 ms |
21516 KB |
Output is correct |
91 |
Correct |
127 ms |
21240 KB |
Output is correct |
92 |
Correct |
129 ms |
22520 KB |
Output is correct |
93 |
Correct |
124 ms |
21752 KB |
Output is correct |
94 |
Correct |
114 ms |
20988 KB |
Output is correct |
95 |
Correct |
121 ms |
22520 KB |
Output is correct |
96 |
Correct |
114 ms |
21244 KB |
Output is correct |
97 |
Correct |
116 ms |
21628 KB |
Output is correct |
98 |
Correct |
118 ms |
21752 KB |
Output is correct |
99 |
Correct |
115 ms |
21496 KB |
Output is correct |
100 |
Correct |
114 ms |
21496 KB |
Output is correct |