#include<bits/stdc++.h>
using namespace std;
int n;
vector<int>v;
vector<long long>table;
struct SegmentTree{
vector<int>segTree;
void init(int n){
segTree.resize(4 * n);
}
void Build(int node, int l, int r, vector<int>&v){
if(l == r){
segTree[node] = v[l];
}
else{
int mid = (l + r) >> 1;
Build(node * 2, l, mid, v);
Build(node * 2 + 1, mid + 1, r, v);
segTree[node] = max(segTree[node * 2], segTree[node * 2 + 1]);
}
}
int Query(int node, int l, int r, int ql, int qr){
if(ql <= l && r <= qr)return segTree[node];
if(ql > r || l > qr)return -1;
int mid = (l + r) >> 1;
int lc = Query(node * 2, l, mid, ql, qr);
int rc = Query(node * 2 + 1, mid + 1, r, ql, qr);
return max(lc, rc);
}
};
SegmentTree tree;
long long rec(int indx){
long long res = 1e18;
if(indx == n + 1)return 0;
if(table[indx] != -1)return table[indx];
for(int i = indx;i <= n;++i){
res = min(res, (long long)(n - indx + 1) * tree.Query(1, 1, n, indx, i) + rec(i + 1));
}
return table[indx] = res;
}
int main()
{
cin >> n;
v.resize(n + 1);
table.assign(n + 1, -1);
for(int i = 1;i <= n;++i)cin >> v[i];
tree.init(n);
tree.Build(1, 1, n, v);
cout << rec(1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
220 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
524 KB |
Output is correct |
2 |
Correct |
100 ms |
516 KB |
Output is correct |
3 |
Correct |
101 ms |
468 KB |
Output is correct |
4 |
Correct |
97 ms |
508 KB |
Output is correct |
5 |
Correct |
107 ms |
520 KB |
Output is correct |
6 |
Correct |
101 ms |
516 KB |
Output is correct |
7 |
Correct |
108 ms |
520 KB |
Output is correct |
8 |
Correct |
95 ms |
468 KB |
Output is correct |
9 |
Correct |
111 ms |
532 KB |
Output is correct |
10 |
Correct |
102 ms |
512 KB |
Output is correct |
11 |
Correct |
106 ms |
468 KB |
Output is correct |
12 |
Correct |
103 ms |
532 KB |
Output is correct |
13 |
Correct |
98 ms |
512 KB |
Output is correct |
14 |
Correct |
110 ms |
516 KB |
Output is correct |
15 |
Correct |
101 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
524 KB |
Output is correct |
2 |
Correct |
100 ms |
516 KB |
Output is correct |
3 |
Correct |
101 ms |
468 KB |
Output is correct |
4 |
Correct |
97 ms |
508 KB |
Output is correct |
5 |
Correct |
107 ms |
520 KB |
Output is correct |
6 |
Correct |
101 ms |
516 KB |
Output is correct |
7 |
Correct |
108 ms |
520 KB |
Output is correct |
8 |
Correct |
95 ms |
468 KB |
Output is correct |
9 |
Correct |
111 ms |
532 KB |
Output is correct |
10 |
Correct |
102 ms |
512 KB |
Output is correct |
11 |
Correct |
106 ms |
468 KB |
Output is correct |
12 |
Correct |
103 ms |
532 KB |
Output is correct |
13 |
Correct |
98 ms |
512 KB |
Output is correct |
14 |
Correct |
110 ms |
516 KB |
Output is correct |
15 |
Correct |
101 ms |
468 KB |
Output is correct |
16 |
Execution timed out |
1084 ms |
173616 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
178208 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
220 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
107 ms |
524 KB |
Output is correct |
16 |
Correct |
100 ms |
516 KB |
Output is correct |
17 |
Correct |
101 ms |
468 KB |
Output is correct |
18 |
Correct |
97 ms |
508 KB |
Output is correct |
19 |
Correct |
107 ms |
520 KB |
Output is correct |
20 |
Correct |
101 ms |
516 KB |
Output is correct |
21 |
Correct |
108 ms |
520 KB |
Output is correct |
22 |
Correct |
95 ms |
468 KB |
Output is correct |
23 |
Correct |
111 ms |
532 KB |
Output is correct |
24 |
Correct |
102 ms |
512 KB |
Output is correct |
25 |
Correct |
106 ms |
468 KB |
Output is correct |
26 |
Correct |
103 ms |
532 KB |
Output is correct |
27 |
Correct |
98 ms |
512 KB |
Output is correct |
28 |
Correct |
110 ms |
516 KB |
Output is correct |
29 |
Correct |
101 ms |
468 KB |
Output is correct |
30 |
Correct |
100 ms |
516 KB |
Output is correct |
31 |
Correct |
105 ms |
468 KB |
Output is correct |
32 |
Correct |
97 ms |
468 KB |
Output is correct |
33 |
Correct |
104 ms |
532 KB |
Output is correct |
34 |
Correct |
99 ms |
468 KB |
Output is correct |
35 |
Correct |
105 ms |
524 KB |
Output is correct |
36 |
Correct |
105 ms |
468 KB |
Output is correct |
37 |
Correct |
112 ms |
516 KB |
Output is correct |
38 |
Correct |
107 ms |
520 KB |
Output is correct |
39 |
Correct |
113 ms |
524 KB |
Output is correct |
40 |
Correct |
97 ms |
512 KB |
Output is correct |
41 |
Correct |
107 ms |
468 KB |
Output is correct |
42 |
Correct |
107 ms |
468 KB |
Output is correct |
43 |
Correct |
107 ms |
524 KB |
Output is correct |
44 |
Correct |
96 ms |
468 KB |
Output is correct |
45 |
Correct |
103 ms |
468 KB |
Output is correct |
46 |
Correct |
98 ms |
512 KB |
Output is correct |
47 |
Correct |
111 ms |
528 KB |
Output is correct |
48 |
Correct |
112 ms |
520 KB |
Output is correct |
49 |
Correct |
104 ms |
468 KB |
Output is correct |
50 |
Correct |
103 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
220 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
107 ms |
524 KB |
Output is correct |
16 |
Correct |
100 ms |
516 KB |
Output is correct |
17 |
Correct |
101 ms |
468 KB |
Output is correct |
18 |
Correct |
97 ms |
508 KB |
Output is correct |
19 |
Correct |
107 ms |
520 KB |
Output is correct |
20 |
Correct |
101 ms |
516 KB |
Output is correct |
21 |
Correct |
108 ms |
520 KB |
Output is correct |
22 |
Correct |
95 ms |
468 KB |
Output is correct |
23 |
Correct |
111 ms |
532 KB |
Output is correct |
24 |
Correct |
102 ms |
512 KB |
Output is correct |
25 |
Correct |
106 ms |
468 KB |
Output is correct |
26 |
Correct |
103 ms |
532 KB |
Output is correct |
27 |
Correct |
98 ms |
512 KB |
Output is correct |
28 |
Correct |
110 ms |
516 KB |
Output is correct |
29 |
Correct |
101 ms |
468 KB |
Output is correct |
30 |
Execution timed out |
1084 ms |
173616 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |