# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
285468 | 2020-08-29T05:40:40 Z | arnold518 | Discharging (NOI20_discharging) | C++14 | 175 ms | 22500 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e6; const ll INF = 1e15; int N; ll dp[MAXN+10], A[MAXN+10]; struct Line { ll a, b; }; double cross(Line p, Line q) { return (double)(q.b-p.b)/(p.a-q.a); } struct CHT { int pos=0; vector<Line> S; void push(Line p) { while(S.size()>1 && cross(S[S.size()-1], S[S.size()-2])>=cross(S[S.size()-1], p)) S.pop_back(); S.push_back(p); } ll query(ll x) { if(pos>=S.size()) pos=S.size()-1; else while(pos+1<S.size() && cross(S[pos], S[pos+1])<=x) pos++; return S[pos].a*x+S[pos].b; } }cht; int main() { scanf("%d", &N); for(int i=1; i<=N; i++) scanf("%lld", &A[i]); reverse(A+1, A+N+1); A[0]=INF; vector<int> S; S.push_back(0); for(int i=1; i<=N; i++) { while(!S.empty() && A[S.back()]<=A[i]) S.pop_back(); S.push_back(i); } for(int i=1; i<S.size(); i++) { cht.push({A[S[i]], dp[i-1]}); dp[i]=cht.query(S[i]); } printf("%lld\n", dp[S.size()-1]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 256 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 0 ms | 384 KB | Output is correct |
12 | Correct | 0 ms | 384 KB | Output is correct |
13 | Correct | 0 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 | 308 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 | 308 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 | 130 ms | 12904 KB | Output is correct |
17 | Correct | 145 ms | 19428 KB | Output is correct |
18 | Correct | 122 ms | 15976 KB | Output is correct |
19 | Correct | 139 ms | 19428 KB | Output is correct |
20 | Correct | 143 ms | 19816 KB | Output is correct |
21 | Correct | 149 ms | 19432 KB | Output is correct |
22 | Correct | 132 ms | 18408 KB | Output is correct |
23 | Correct | 149 ms | 21744 KB | Output is correct |
24 | Correct | 149 ms | 20576 KB | Output is correct |
25 | Correct | 149 ms | 20824 KB | Output is correct |
26 | Correct | 153 ms | 22500 KB | Output is correct |
27 | Correct | 145 ms | 17384 KB | Output is correct |
28 | Correct | 142 ms | 19688 KB | Output is correct |
29 | Correct | 146 ms | 20836 KB | Output is correct |
30 | Correct | 150 ms | 21988 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 163 ms | 8184 KB | Output is correct |
2 | Correct | 160 ms | 8252 KB | Output is correct |
3 | Correct | 164 ms | 8188 KB | Output is correct |
4 | Correct | 162 ms | 8184 KB | Output is correct |
5 | Correct | 159 ms | 8184 KB | Output is correct |
6 | Correct | 157 ms | 8184 KB | Output is correct |
7 | Correct | 162 ms | 8184 KB | Output is correct |
8 | Correct | 160 ms | 8312 KB | Output is correct |
9 | Correct | 165 ms | 8184 KB | Output is correct |
10 | Correct | 153 ms | 8184 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 256 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 0 ms | 384 KB | Output is correct |
12 | Correct | 0 ms | 384 KB | Output is correct |
13 | Correct | 0 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 | 308 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 | 384 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 | 384 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 | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 256 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 0 ms | 384 KB | Output is correct |
12 | Correct | 0 ms | 384 KB | Output is correct |
13 | Correct | 0 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 | 308 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 | 130 ms | 12904 KB | Output is correct |
31 | Correct | 145 ms | 19428 KB | Output is correct |
32 | Correct | 122 ms | 15976 KB | Output is correct |
33 | Correct | 139 ms | 19428 KB | Output is correct |
34 | Correct | 143 ms | 19816 KB | Output is correct |
35 | Correct | 149 ms | 19432 KB | Output is correct |
36 | Correct | 132 ms | 18408 KB | Output is correct |
37 | Correct | 149 ms | 21744 KB | Output is correct |
38 | Correct | 149 ms | 20576 KB | Output is correct |
39 | Correct | 149 ms | 20824 KB | Output is correct |
40 | Correct | 153 ms | 22500 KB | Output is correct |
41 | Correct | 145 ms | 17384 KB | Output is correct |
42 | Correct | 142 ms | 19688 KB | Output is correct |
43 | Correct | 146 ms | 20836 KB | Output is correct |
44 | Correct | 150 ms | 21988 KB | Output is correct |
45 | Correct | 163 ms | 8184 KB | Output is correct |
46 | Correct | 160 ms | 8252 KB | Output is correct |
47 | Correct | 164 ms | 8188 KB | Output is correct |
48 | Correct | 162 ms | 8184 KB | Output is correct |
49 | Correct | 159 ms | 8184 KB | Output is correct |
50 | Correct | 157 ms | 8184 KB | Output is correct |
51 | Correct | 162 ms | 8184 KB | Output is correct |
52 | Correct | 160 ms | 8312 KB | Output is correct |
53 | Correct | 165 ms | 8184 KB | Output is correct |
54 | Correct | 153 ms | 8184 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 | 384 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 | 384 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 | 162 ms | 14148 KB | Output is correct |
77 | Correct | 173 ms | 14136 KB | Output is correct |
78 | Correct | 147 ms | 13608 KB | Output is correct |
79 | Correct | 158 ms | 13816 KB | Output is correct |
80 | Correct | 155 ms | 14412 KB | Output is correct |
81 | Correct | 152 ms | 13816 KB | Output is correct |
82 | Correct | 151 ms | 13688 KB | Output is correct |
83 | Correct | 154 ms | 14072 KB | Output is correct |
84 | Correct | 148 ms | 13944 KB | Output is correct |
85 | Correct | 168 ms | 14200 KB | Output is correct |
86 | Correct | 156 ms | 13568 KB | Output is correct |
87 | Correct | 146 ms | 13432 KB | Output is correct |
88 | Correct | 152 ms | 13816 KB | Output is correct |
89 | Correct | 145 ms | 13688 KB | Output is correct |
90 | Correct | 147 ms | 13660 KB | Output is correct |
91 | Correct | 143 ms | 13392 KB | Output is correct |
92 | Correct | 153 ms | 21096 KB | Output is correct |
93 | Correct | 147 ms | 19452 KB | Output is correct |
94 | Correct | 153 ms | 13176 KB | Output is correct |
95 | Correct | 160 ms | 14584 KB | Output is correct |
96 | Correct | 143 ms | 13432 KB | Output is correct |
97 | Correct | 175 ms | 13688 KB | Output is correct |
98 | Correct | 147 ms | 13948 KB | Output is correct |
99 | Correct | 146 ms | 13564 KB | Output is correct |
100 | Correct | 146 ms | 13688 KB | Output is correct |