# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088766 | 2024-09-15T02:24:50 Z | vjudge1 | Discharging (NOI20_discharging) | C++17 | 126 ms | 25716 KB |
#include<bits/stdc++.h> #define taskname "" #define el '\n' #define fi first #define sc second #define pii pair<int, int> #define all(v) v.begin(), v.end() #define int long long using namespace std; #define Faster ios_base::sync_with_stdio(false);cin.tie(0); const int maxn=1e6+33; const int N=1e5; const int mod=1e9+7; const long long INF=1e18+2; int n,cost[1505][1505],a[maxn]; int dp[maxn]; void sub1() { for(int i=1;i<=n;i++) { cost[i][i]=a[i]; for(int j=i+1;j<=n;j++) { cost[i][j]=max(cost[i][j-1],a[j]); } } for(int i=1;i<=n;i++) { dp[i]=cost[1][i]*n; for(int j=1;j<i;j++) { dp[i]=min(dp[i],dp[j]+cost[j+1][i]*(n-j)); } } cout<<dp[n]; } struct line { int a,b; }; long double intersect(line x,line y) { return -1.0*(x.b-y.b)/(x.a-y.a); } vector<line> cht; vector<long double> point; void add(line x) { while(!cht.empty()&&intersect(x,cht.back())<=point.back()) { cht.pop_back(); point.pop_back(); } point.push_back(intersect(cht.back(),x)); cht.push_back(x); } int get(int x) { int kk=upper_bound(point.begin(),point.end(),x)-point.begin()-1; return cht[kk].a*x+cht[kk].b; } void sub2() { int Max=0; cht.push_back({0,0}); point.push_back(-INF); for(int i=1;i<=n;i++) { if(a[i]<=Max) a[i]=Max; if(a[i]>Max) { Max=a[i]; } dp[i]=get(a[i])+n*a[i]; add({-i,dp[i]}); } cout<<dp[n]; } signed main() { if (fopen(taskname".INP","r")) { freopen(taskname".INP","r",stdin); freopen(taskname".OUT","w",stdout); } Faster cin>>n; int inc=0,dec=0; for(int i=1;i<=n;i++) { cin>>a[i]; if(i>1&&a[i]>a[i-1]) inc=1; if(i>1&&a[i]<a[i-1]) dec=1; } if(n<=1500) sub1(); else sub2(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 13916 KB | Output is correct |
2 | Correct | 8 ms | 13224 KB | Output is correct |
3 | Correct | 10 ms | 13656 KB | Output is correct |
4 | Correct | 7 ms | 13148 KB | Output is correct |
5 | Correct | 8 ms | 14172 KB | Output is correct |
6 | Correct | 7 ms | 13660 KB | Output is correct |
7 | Correct | 7 ms | 13660 KB | Output is correct |
8 | Correct | 7 ms | 13148 KB | Output is correct |
9 | Correct | 8 ms | 13912 KB | Output is correct |
10 | Correct | 9 ms | 13144 KB | Output is correct |
11 | Correct | 9 ms | 13916 KB | Output is correct |
12 | Correct | 10 ms | 13660 KB | Output is correct |
13 | Correct | 8 ms | 13148 KB | Output is correct |
14 | Correct | 8 ms | 14172 KB | Output is correct |
15 | Correct | 8 ms | 13404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 13916 KB | Output is correct |
2 | Correct | 8 ms | 13224 KB | Output is correct |
3 | Correct | 10 ms | 13656 KB | Output is correct |
4 | Correct | 7 ms | 13148 KB | Output is correct |
5 | Correct | 8 ms | 14172 KB | Output is correct |
6 | Correct | 7 ms | 13660 KB | Output is correct |
7 | Correct | 7 ms | 13660 KB | Output is correct |
8 | Correct | 7 ms | 13148 KB | Output is correct |
9 | Correct | 8 ms | 13912 KB | Output is correct |
10 | Correct | 9 ms | 13144 KB | Output is correct |
11 | Correct | 9 ms | 13916 KB | Output is correct |
12 | Correct | 10 ms | 13660 KB | Output is correct |
13 | Correct | 8 ms | 13148 KB | Output is correct |
14 | Correct | 8 ms | 14172 KB | Output is correct |
15 | Correct | 8 ms | 13404 KB | Output is correct |
16 | Correct | 80 ms | 20908 KB | Output is correct |
17 | Correct | 97 ms | 21872 KB | Output is correct |
18 | Correct | 75 ms | 20432 KB | Output is correct |
19 | Correct | 93 ms | 21900 KB | Output is correct |
20 | Correct | 87 ms | 21584 KB | Output is correct |
21 | Correct | 90 ms | 21780 KB | Output is correct |
22 | Correct | 93 ms | 21316 KB | Output is correct |
23 | Correct | 89 ms | 22356 KB | Output is correct |
24 | Correct | 86 ms | 21924 KB | Output is correct |
25 | Correct | 89 ms | 22244 KB | Output is correct |
26 | Correct | 112 ms | 22708 KB | Output is correct |
27 | Correct | 79 ms | 21072 KB | Output is correct |
28 | Correct | 89 ms | 21844 KB | Output is correct |
29 | Correct | 91 ms | 22128 KB | Output is correct |
30 | Correct | 91 ms | 22388 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 92 ms | 25680 KB | Output is correct |
2 | Correct | 108 ms | 25716 KB | Output is correct |
3 | Correct | 94 ms | 25512 KB | Output is correct |
4 | Correct | 126 ms | 25680 KB | Output is correct |
5 | Correct | 90 ms | 25680 KB | Output is correct |
6 | Correct | 95 ms | 25708 KB | Output is correct |
7 | Correct | 121 ms | 25540 KB | Output is correct |
8 | Correct | 101 ms | 25684 KB | Output is correct |
9 | Correct | 89 ms | 25680 KB | Output is correct |
10 | Correct | 94 ms | 25684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 344 KB | Output is correct |
15 | Correct | 10 ms | 13916 KB | Output is correct |
16 | Correct | 8 ms | 13224 KB | Output is correct |
17 | Correct | 10 ms | 13656 KB | Output is correct |
18 | Correct | 7 ms | 13148 KB | Output is correct |
19 | Correct | 8 ms | 14172 KB | Output is correct |
20 | Correct | 7 ms | 13660 KB | Output is correct |
21 | Correct | 7 ms | 13660 KB | Output is correct |
22 | Correct | 7 ms | 13148 KB | Output is correct |
23 | Correct | 8 ms | 13912 KB | Output is correct |
24 | Correct | 9 ms | 13144 KB | Output is correct |
25 | Correct | 9 ms | 13916 KB | Output is correct |
26 | Correct | 10 ms | 13660 KB | Output is correct |
27 | Correct | 8 ms | 13148 KB | Output is correct |
28 | Correct | 8 ms | 14172 KB | Output is correct |
29 | Correct | 8 ms | 13404 KB | Output is correct |
30 | Correct | 7 ms | 13400 KB | Output is correct |
31 | Correct | 9 ms | 13916 KB | Output is correct |
32 | Correct | 7 ms | 13272 KB | Output is correct |
33 | Correct | 8 ms | 13828 KB | Output is correct |
34 | Correct | 7 ms | 13404 KB | Output is correct |
35 | Correct | 9 ms | 14020 KB | Output is correct |
36 | Correct | 8 ms | 13916 KB | Output is correct |
37 | Correct | 9 ms | 13912 KB | Output is correct |
38 | Correct | 7 ms | 14024 KB | Output is correct |
39 | Correct | 12 ms | 13912 KB | Output is correct |
40 | Correct | 7 ms | 13148 KB | Output is correct |
41 | Correct | 7 ms | 13748 KB | Output is correct |
42 | Correct | 9 ms | 14124 KB | Output is correct |
43 | Correct | 8 ms | 14172 KB | Output is correct |
44 | Correct | 7 ms | 13484 KB | Output is correct |
45 | Correct | 11 ms | 13528 KB | Output is correct |
46 | Correct | 8 ms | 13400 KB | Output is correct |
47 | Correct | 8 ms | 14172 KB | Output is correct |
48 | Correct | 8 ms | 13148 KB | Output is correct |
49 | Correct | 8 ms | 13120 KB | Output is correct |
50 | Correct | 7 ms | 13148 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 344 KB | Output is correct |
15 | Correct | 10 ms | 13916 KB | Output is correct |
16 | Correct | 8 ms | 13224 KB | Output is correct |
17 | Correct | 10 ms | 13656 KB | Output is correct |
18 | Correct | 7 ms | 13148 KB | Output is correct |
19 | Correct | 8 ms | 14172 KB | Output is correct |
20 | Correct | 7 ms | 13660 KB | Output is correct |
21 | Correct | 7 ms | 13660 KB | Output is correct |
22 | Correct | 7 ms | 13148 KB | Output is correct |
23 | Correct | 8 ms | 13912 KB | Output is correct |
24 | Correct | 9 ms | 13144 KB | Output is correct |
25 | Correct | 9 ms | 13916 KB | Output is correct |
26 | Correct | 10 ms | 13660 KB | Output is correct |
27 | Correct | 8 ms | 13148 KB | Output is correct |
28 | Correct | 8 ms | 14172 KB | Output is correct |
29 | Correct | 8 ms | 13404 KB | Output is correct |
30 | Correct | 80 ms | 20908 KB | Output is correct |
31 | Correct | 97 ms | 21872 KB | Output is correct |
32 | Correct | 75 ms | 20432 KB | Output is correct |
33 | Correct | 93 ms | 21900 KB | Output is correct |
34 | Correct | 87 ms | 21584 KB | Output is correct |
35 | Correct | 90 ms | 21780 KB | Output is correct |
36 | Correct | 93 ms | 21316 KB | Output is correct |
37 | Correct | 89 ms | 22356 KB | Output is correct |
38 | Correct | 86 ms | 21924 KB | Output is correct |
39 | Correct | 89 ms | 22244 KB | Output is correct |
40 | Correct | 112 ms | 22708 KB | Output is correct |
41 | Correct | 79 ms | 21072 KB | Output is correct |
42 | Correct | 89 ms | 21844 KB | Output is correct |
43 | Correct | 91 ms | 22128 KB | Output is correct |
44 | Correct | 91 ms | 22388 KB | Output is correct |
45 | Correct | 92 ms | 25680 KB | Output is correct |
46 | Correct | 108 ms | 25716 KB | Output is correct |
47 | Correct | 94 ms | 25512 KB | Output is correct |
48 | Correct | 126 ms | 25680 KB | Output is correct |
49 | Correct | 90 ms | 25680 KB | Output is correct |
50 | Correct | 95 ms | 25708 KB | Output is correct |
51 | Correct | 121 ms | 25540 KB | Output is correct |
52 | Correct | 101 ms | 25684 KB | Output is correct |
53 | Correct | 89 ms | 25680 KB | Output is correct |
54 | Correct | 94 ms | 25684 KB | Output is correct |
55 | Correct | 7 ms | 13400 KB | Output is correct |
56 | Correct | 9 ms | 13916 KB | Output is correct |
57 | Correct | 7 ms | 13272 KB | Output is correct |
58 | Correct | 8 ms | 13828 KB | Output is correct |
59 | Correct | 7 ms | 13404 KB | Output is correct |
60 | Correct | 9 ms | 14020 KB | Output is correct |
61 | Correct | 8 ms | 13916 KB | Output is correct |
62 | Correct | 9 ms | 13912 KB | Output is correct |
63 | Correct | 7 ms | 14024 KB | Output is correct |
64 | Correct | 12 ms | 13912 KB | Output is correct |
65 | Correct | 7 ms | 13148 KB | Output is correct |
66 | Correct | 7 ms | 13748 KB | Output is correct |
67 | Correct | 9 ms | 14124 KB | Output is correct |
68 | Correct | 8 ms | 14172 KB | Output is correct |
69 | Correct | 7 ms | 13484 KB | Output is correct |
70 | Correct | 11 ms | 13528 KB | Output is correct |
71 | Correct | 8 ms | 13400 KB | Output is correct |
72 | Correct | 8 ms | 14172 KB | Output is correct |
73 | Correct | 8 ms | 13148 KB | Output is correct |
74 | Correct | 8 ms | 13120 KB | Output is correct |
75 | Correct | 7 ms | 13148 KB | Output is correct |
76 | Correct | 80 ms | 22096 KB | Output is correct |
77 | Correct | 86 ms | 21956 KB | Output is correct |
78 | Correct | 76 ms | 21332 KB | Output is correct |
79 | Correct | 77 ms | 21588 KB | Output is correct |
80 | Correct | 85 ms | 22424 KB | Output is correct |
81 | Correct | 94 ms | 21584 KB | Output is correct |
82 | Correct | 82 ms | 21588 KB | Output is correct |
83 | Correct | 78 ms | 21840 KB | Output is correct |
84 | Correct | 76 ms | 21904 KB | Output is correct |
85 | Correct | 83 ms | 22100 KB | Output is correct |
86 | Correct | 86 ms | 21416 KB | Output is correct |
87 | Correct | 79 ms | 21212 KB | Output is correct |
88 | Correct | 83 ms | 21728 KB | Output is correct |
89 | Correct | 82 ms | 21588 KB | Output is correct |
90 | Correct | 77 ms | 21692 KB | Output is correct |
91 | Correct | 81 ms | 21120 KB | Output is correct |
92 | Correct | 95 ms | 22592 KB | Output is correct |
93 | Correct | 86 ms | 21844 KB | Output is correct |
94 | Correct | 73 ms | 20820 KB | Output is correct |
95 | Correct | 87 ms | 22396 KB | Output is correct |
96 | Correct | 78 ms | 21300 KB | Output is correct |
97 | Correct | 78 ms | 21580 KB | Output is correct |
98 | Correct | 91 ms | 21844 KB | Output is correct |
99 | Correct | 78 ms | 21520 KB | Output is correct |
100 | Correct | 79 ms | 21588 KB | Output is correct |