#define local
#ifndef local
#include ""
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 3e5 + 5;
const int oo = 1e18 + 7, mod = 1e9 + 7;
mt19937 rng(1);
int rnd(int l, int r){
int temp = rng() % (r - l + 1);
return abs(temp) + l;
}
int n, a[N];
vector<vector<int>> cal(int l, int r){// from left to right: (0,0), (0,1), (1,0), (1,1)
if(l == r){
vector<vector<int>> v;
v.pb({0, 0});
v.pb({0, 0});
v.pb({0, 0});
v.pb({0, a[l]});
return v;
}
int mid = (l + r) >> 1;
vector<vector<int>> cal1 = cal(l, mid), cal2 = cal(mid + 1, r);
vector<vector<int>> ans;
for(int i = 0; i <= 3; i++){
vector<int> temp;
temp.resize(r - l + 2);
ans.pb(temp);
}
//int want = (l + r + 1) >> 1;
for(int le = 0; le < 2; le++){
for(int ri = 0; ri < 2; ri++){
for(int mile = 0; mile < 2; mile++){
for(int miri = 0; miri < 2; miri++){
if(mile & miri) continue;
int cur_opt = 0;
int temp1 = (mid - l + 1 - (1 - le) - (1 - mile) + 1) / 2, temp2 = (r - mid - (1 - ri) - (1 - miri) + 1) / 2;
// cout << temp1 << " " << temp2 << "\n";
for(int tol = 0; tol <= temp1 + temp2; tol++){
while(tol - cur_opt > temp2) cur_opt++;
while(cur_opt < min(temp1, tol)){
// cout << cur_opt << "\n";
int val1 = cal1[(le << 1) | mile][cur_opt] + cal2[(miri << 1) | ri][tol - cur_opt];
int val2 = cal1[(le << 1) | mile][cur_opt + 1] + cal2[(miri << 1) | ri][tol - cur_opt - 1];
// cout << val1 << " " << val2 << "\n";
if(val1 < val2) cur_opt++;
else break;
}
// cout << le << " " << ri << " " << mile << " " << miri << " " << tol << " " << cur_opt << " " << cal1[(le << 1) | mile][cur_opt] + cal2[(miri << 1) | ri][tol - cur_opt] << "\n";
ans[(le << 1) | ri][tol] = max(ans[(le << 1) | ri][tol], cal1[(le << 1) | mile][cur_opt] + cal2[(miri << 1) | ri][tol - cur_opt]);
}
}
}
}
}
//cout << l << " " << r << "\n";
for(int i = 0; i < 4; i++){
// cout << "OK ";
// for(int j = 0; j < ans[i].size(); j++) cout << ans[i][j] << " ";
// cout << "\n";
}
return ans;
}
#ifdef local
void process(){
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
vector<vector<int>> v = cal(1, n);
for(int i = 1; i <= (n + 1)/2; i++) cout << max({v[0][i], v[1][i], v[2][i], v[3][i]}) << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
process();
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
472 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
464 KB |
Output is correct |
14 |
Correct |
2 ms |
476 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
472 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
464 KB |
Output is correct |
14 |
Correct |
2 ms |
476 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
223 ms |
19420 KB |
Output is correct |
22 |
Correct |
218 ms |
19376 KB |
Output is correct |
23 |
Correct |
220 ms |
19412 KB |
Output is correct |
24 |
Correct |
186 ms |
19392 KB |
Output is correct |
25 |
Correct |
180 ms |
19328 KB |
Output is correct |
26 |
Correct |
207 ms |
19236 KB |
Output is correct |
27 |
Correct |
183 ms |
19496 KB |
Output is correct |
28 |
Correct |
191 ms |
19408 KB |
Output is correct |
29 |
Correct |
186 ms |
19464 KB |
Output is correct |
30 |
Correct |
198 ms |
19400 KB |
Output is correct |
31 |
Correct |
186 ms |
19480 KB |
Output is correct |
32 |
Correct |
207 ms |
19516 KB |
Output is correct |
33 |
Correct |
196 ms |
19256 KB |
Output is correct |
34 |
Correct |
199 ms |
19264 KB |
Output is correct |
35 |
Correct |
230 ms |
19276 KB |
Output is correct |
36 |
Correct |
224 ms |
19400 KB |
Output is correct |
37 |
Correct |
232 ms |
19492 KB |
Output is correct |
38 |
Correct |
216 ms |
19388 KB |
Output is correct |
39 |
Correct |
179 ms |
19224 KB |
Output is correct |
40 |
Correct |
191 ms |
19220 KB |
Output is correct |
41 |
Correct |
179 ms |
19272 KB |
Output is correct |
42 |
Correct |
185 ms |
19448 KB |
Output is correct |
43 |
Correct |
207 ms |
19484 KB |
Output is correct |
44 |
Correct |
187 ms |
19524 KB |
Output is correct |
45 |
Correct |
185 ms |
19528 KB |
Output is correct |
46 |
Correct |
184 ms |
19496 KB |
Output is correct |
47 |
Correct |
188 ms |
19504 KB |
Output is correct |
48 |
Correct |
195 ms |
19268 KB |
Output is correct |
49 |
Correct |
221 ms |
19328 KB |
Output is correct |
50 |
Correct |
198 ms |
19180 KB |
Output is correct |