#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r)
{
return l+rng()%(r-l+1);
}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define forinc(x,a,b) for(int x=a;x<=b;x++)
#define fordec(x,a,b) for(int x=a;x>=b;x--)
#define iii pair<ii,int>
#define fi first
#define se second
#define ii pair<int,int>
#define getbit(x,i) ((x>>(i))&1)
#define batbit(x,i) (x|(1ll<<(i)))
#define tatbit(x,i) (x&~(1<<(i)))
#define endl '\n'
#define pb push_back
#define int long long
const int N = 1e6 + 10;
int n, t[N];
int f[N][23];
int lg[N];
int dp[N];
int get(int l, int r)
{
int p = lg[r-l+1];
return max(f[l][p] , f[r - (1<<p) + 1][p]);
}
int cost(int j, int i)
{
return dp[j] + get(j+1,i)*(n-j);
}
int inc=1;
int decc=1;
main()
{
//freopen("task.inp" , "r" , stdin);
fasty;
cin >> n;
forinc(i,1,n)
{
cin >> t[i];
f[i][0] = t[i];
}
forinc(i,1,n-1)
{
if(t[i] > t[i+1]) inc=0;
if(t[i] < t[i+1]) decc=0;
}
forinc(i,2,n) lg[i] = lg[i/2] + 1;
forinc(j,1,20)
{
for(int i=1 ; i + (1<<j) - 1 <= n ; i++)
{
f[i][j] = max(f[i][j-1] , f[i + (1<<(j-1) )][j-1]);
}
}
if(n<=7000)
{
memset(dp , 127, sizeof dp);
dp[0]=0;
forinc(i,1,n)
{
fordec(j,i-1,0) dp[i] = min(dp[i] ,cost(j,i));
}
cout << dp[n];
return 0;
}
if(decc == 1)
{
int sum=0;
int res = t[1] * n;
cout << res << "\n";
return 0;
}
}
Compilation message
Discharging.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
37 | main()
| ^~~~
Discharging.cpp: In function 'int main()':
Discharging.cpp:73:13: warning: unused variable 'sum' [-Wunused-variable]
73 | int sum=0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8140 KB |
Output is correct |
2 |
Correct |
3 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
3 ms |
8164 KB |
Output is correct |
6 |
Correct |
4 ms |
8144 KB |
Output is correct |
7 |
Correct |
5 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
4 ms |
8148 KB |
Output is correct |
10 |
Correct |
4 ms |
8148 KB |
Output is correct |
11 |
Correct |
3 ms |
8148 KB |
Output is correct |
12 |
Correct |
3 ms |
8148 KB |
Output is correct |
13 |
Correct |
3 ms |
8148 KB |
Output is correct |
14 |
Correct |
3 ms |
8136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8532 KB |
Output is correct |
2 |
Correct |
6 ms |
8404 KB |
Output is correct |
3 |
Correct |
8 ms |
8404 KB |
Output is correct |
4 |
Correct |
7 ms |
8408 KB |
Output is correct |
5 |
Correct |
8 ms |
8404 KB |
Output is correct |
6 |
Correct |
7 ms |
8404 KB |
Output is correct |
7 |
Correct |
7 ms |
8404 KB |
Output is correct |
8 |
Correct |
7 ms |
8404 KB |
Output is correct |
9 |
Correct |
9 ms |
8404 KB |
Output is correct |
10 |
Correct |
7 ms |
8396 KB |
Output is correct |
11 |
Correct |
8 ms |
8404 KB |
Output is correct |
12 |
Correct |
9 ms |
8404 KB |
Output is correct |
13 |
Correct |
7 ms |
8404 KB |
Output is correct |
14 |
Correct |
7 ms |
8404 KB |
Output is correct |
15 |
Correct |
6 ms |
8400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8532 KB |
Output is correct |
2 |
Correct |
6 ms |
8404 KB |
Output is correct |
3 |
Correct |
8 ms |
8404 KB |
Output is correct |
4 |
Correct |
7 ms |
8408 KB |
Output is correct |
5 |
Correct |
8 ms |
8404 KB |
Output is correct |
6 |
Correct |
7 ms |
8404 KB |
Output is correct |
7 |
Correct |
7 ms |
8404 KB |
Output is correct |
8 |
Correct |
7 ms |
8404 KB |
Output is correct |
9 |
Correct |
9 ms |
8404 KB |
Output is correct |
10 |
Correct |
7 ms |
8396 KB |
Output is correct |
11 |
Correct |
8 ms |
8404 KB |
Output is correct |
12 |
Correct |
9 ms |
8404 KB |
Output is correct |
13 |
Correct |
7 ms |
8404 KB |
Output is correct |
14 |
Correct |
7 ms |
8404 KB |
Output is correct |
15 |
Correct |
6 ms |
8400 KB |
Output is correct |
16 |
Incorrect |
315 ms |
201080 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
342 ms |
205764 KB |
Output is correct |
2 |
Correct |
349 ms |
205696 KB |
Output is correct |
3 |
Correct |
363 ms |
205684 KB |
Output is correct |
4 |
Correct |
362 ms |
205692 KB |
Output is correct |
5 |
Correct |
348 ms |
205808 KB |
Output is correct |
6 |
Correct |
360 ms |
205764 KB |
Output is correct |
7 |
Correct |
333 ms |
205608 KB |
Output is correct |
8 |
Correct |
350 ms |
205696 KB |
Output is correct |
9 |
Correct |
332 ms |
205692 KB |
Output is correct |
10 |
Correct |
359 ms |
205716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8140 KB |
Output is correct |
2 |
Correct |
3 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
3 ms |
8164 KB |
Output is correct |
6 |
Correct |
4 ms |
8144 KB |
Output is correct |
7 |
Correct |
5 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
4 ms |
8148 KB |
Output is correct |
10 |
Correct |
4 ms |
8148 KB |
Output is correct |
11 |
Correct |
3 ms |
8148 KB |
Output is correct |
12 |
Correct |
3 ms |
8148 KB |
Output is correct |
13 |
Correct |
3 ms |
8148 KB |
Output is correct |
14 |
Correct |
3 ms |
8136 KB |
Output is correct |
15 |
Correct |
7 ms |
8532 KB |
Output is correct |
16 |
Correct |
6 ms |
8404 KB |
Output is correct |
17 |
Correct |
8 ms |
8404 KB |
Output is correct |
18 |
Correct |
7 ms |
8408 KB |
Output is correct |
19 |
Correct |
8 ms |
8404 KB |
Output is correct |
20 |
Correct |
7 ms |
8404 KB |
Output is correct |
21 |
Correct |
7 ms |
8404 KB |
Output is correct |
22 |
Correct |
7 ms |
8404 KB |
Output is correct |
23 |
Correct |
9 ms |
8404 KB |
Output is correct |
24 |
Correct |
7 ms |
8396 KB |
Output is correct |
25 |
Correct |
8 ms |
8404 KB |
Output is correct |
26 |
Correct |
9 ms |
8404 KB |
Output is correct |
27 |
Correct |
7 ms |
8404 KB |
Output is correct |
28 |
Correct |
7 ms |
8404 KB |
Output is correct |
29 |
Correct |
6 ms |
8400 KB |
Output is correct |
30 |
Correct |
7 ms |
8404 KB |
Output is correct |
31 |
Correct |
9 ms |
8480 KB |
Output is correct |
32 |
Correct |
6 ms |
8488 KB |
Output is correct |
33 |
Correct |
7 ms |
8404 KB |
Output is correct |
34 |
Correct |
7 ms |
8404 KB |
Output is correct |
35 |
Correct |
7 ms |
8400 KB |
Output is correct |
36 |
Correct |
7 ms |
8404 KB |
Output is correct |
37 |
Correct |
7 ms |
8404 KB |
Output is correct |
38 |
Correct |
7 ms |
8404 KB |
Output is correct |
39 |
Correct |
7 ms |
8400 KB |
Output is correct |
40 |
Correct |
7 ms |
8404 KB |
Output is correct |
41 |
Correct |
7 ms |
8404 KB |
Output is correct |
42 |
Correct |
7 ms |
8404 KB |
Output is correct |
43 |
Correct |
7 ms |
8404 KB |
Output is correct |
44 |
Correct |
8 ms |
8404 KB |
Output is correct |
45 |
Correct |
9 ms |
8404 KB |
Output is correct |
46 |
Correct |
6 ms |
8400 KB |
Output is correct |
47 |
Correct |
7 ms |
8404 KB |
Output is correct |
48 |
Correct |
6 ms |
8404 KB |
Output is correct |
49 |
Correct |
6 ms |
8404 KB |
Output is correct |
50 |
Correct |
6 ms |
8404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8140 KB |
Output is correct |
2 |
Correct |
3 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
3 ms |
8164 KB |
Output is correct |
6 |
Correct |
4 ms |
8144 KB |
Output is correct |
7 |
Correct |
5 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
4 ms |
8148 KB |
Output is correct |
10 |
Correct |
4 ms |
8148 KB |
Output is correct |
11 |
Correct |
3 ms |
8148 KB |
Output is correct |
12 |
Correct |
3 ms |
8148 KB |
Output is correct |
13 |
Correct |
3 ms |
8148 KB |
Output is correct |
14 |
Correct |
3 ms |
8136 KB |
Output is correct |
15 |
Correct |
7 ms |
8532 KB |
Output is correct |
16 |
Correct |
6 ms |
8404 KB |
Output is correct |
17 |
Correct |
8 ms |
8404 KB |
Output is correct |
18 |
Correct |
7 ms |
8408 KB |
Output is correct |
19 |
Correct |
8 ms |
8404 KB |
Output is correct |
20 |
Correct |
7 ms |
8404 KB |
Output is correct |
21 |
Correct |
7 ms |
8404 KB |
Output is correct |
22 |
Correct |
7 ms |
8404 KB |
Output is correct |
23 |
Correct |
9 ms |
8404 KB |
Output is correct |
24 |
Correct |
7 ms |
8396 KB |
Output is correct |
25 |
Correct |
8 ms |
8404 KB |
Output is correct |
26 |
Correct |
9 ms |
8404 KB |
Output is correct |
27 |
Correct |
7 ms |
8404 KB |
Output is correct |
28 |
Correct |
7 ms |
8404 KB |
Output is correct |
29 |
Correct |
6 ms |
8400 KB |
Output is correct |
30 |
Incorrect |
315 ms |
201080 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |