///
/// What would happen if we used assembly language for CP?
/// Sorry, that was a strange thing to ask.
///
#include <bits/stdc++.h>
#define Loop(x,l,r) for(ll x = ll(l); x < ll(r); ++x)
#define LoopR(x,l,r) for(ll x = ll(r)-1; x >= ll(l); --x)
#define Kill(x) exit((cout << (x) << '\n', 0))
typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx")
#define max(x,y) ((x)>(y)?(x):(y))
const int N = 200'010;
double dp[4][N];
int a[N];
int n;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n;
Loop(i,0,n) cin >> a[i];
Loop(_,0,n)
{
const double x = a[_];
const int i = (_+1)&3;
const int r = (_+2)/2;
switch(i){
case 0:
Loop(j,1,r)
dp[0][j] = max(dp[3][j], dp[2][j-1]+x);
break;
case 1:
Loop(j,1,r)
dp[1][j] = max(dp[0][j], dp[3][j-1]+x);
break;
case 2:
Loop(j,1,r)
dp[2][j] = max(dp[1][j], dp[0][j-1]+x);
break;
case 3:
Loop(j,1,r)
dp[3][j] = max(dp[2][j], dp[1][j-1]+x);
break;
}
dp[i][0] = max(dp[(i+3)&3][0], x);
}
Loop(i,0,(n+1)/2) cout << (ll)dp[n&3][i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
408 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
408 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
4779 ms |
7616 KB |
Output is correct |
22 |
Correct |
4807 ms |
7564 KB |
Output is correct |
23 |
Correct |
4566 ms |
7656 KB |
Output is correct |
24 |
Correct |
4807 ms |
7468 KB |
Output is correct |
25 |
Correct |
4553 ms |
7504 KB |
Output is correct |
26 |
Correct |
4629 ms |
7432 KB |
Output is correct |
27 |
Correct |
4554 ms |
7688 KB |
Output is correct |
28 |
Correct |
4625 ms |
7600 KB |
Output is correct |
29 |
Correct |
4767 ms |
7584 KB |
Output is correct |
30 |
Correct |
4705 ms |
7556 KB |
Output is correct |
31 |
Correct |
4738 ms |
7664 KB |
Output is correct |
32 |
Correct |
4944 ms |
7580 KB |
Output is correct |
33 |
Correct |
4327 ms |
7376 KB |
Output is correct |
34 |
Correct |
4729 ms |
7472 KB |
Output is correct |
35 |
Correct |
4655 ms |
7408 KB |
Output is correct |
36 |
Correct |
4454 ms |
7616 KB |
Output is correct |
37 |
Correct |
4600 ms |
7548 KB |
Output is correct |
38 |
Correct |
4480 ms |
7708 KB |
Output is correct |
39 |
Correct |
4632 ms |
7432 KB |
Output is correct |
40 |
Correct |
4657 ms |
7508 KB |
Output is correct |
41 |
Correct |
4848 ms |
7492 KB |
Output is correct |
42 |
Correct |
4436 ms |
7760 KB |
Output is correct |
43 |
Correct |
4496 ms |
7756 KB |
Output is correct |
44 |
Correct |
4181 ms |
7744 KB |
Output is correct |
45 |
Correct |
4289 ms |
7580 KB |
Output is correct |
46 |
Correct |
4502 ms |
7620 KB |
Output is correct |
47 |
Correct |
4232 ms |
7640 KB |
Output is correct |
48 |
Correct |
4456 ms |
7524 KB |
Output is correct |
49 |
Correct |
4389 ms |
7588 KB |
Output is correct |
50 |
Correct |
4181 ms |
7400 KB |
Output is correct |