#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
cin.tie(0) -> sync_with_stdio(0);
#ifndef ONLINE_JUDGE
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
// freopen("inp.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#else
#define er(args ...) 0
#endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 998244353, maxn = 1000 + 5, sq = 400, ln = maxn/sq + 5, lg = 22, inf = ll(1e18) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll,md);return k*k%md*(b&1ll?a:1)%md;}
int a[maxn];
vector<ll> comb(vector<ll> a, vector<ll> b){
vector<ll> res(sz(a) + sz(b) - 1);
rep(i,0,sz(res)){
int l = max(0, i - sz(b) + 1);
int r = min(sz(a)-1, i) + 1;
auto get = [&](int x){
return a[x] + b[i - x];
};
while(l + 1 < r){
int mid = (l + r)>>1;
ll w = get(mid) - get(mid-1);
if(w > 0) l = mid;
else r = mid;
}
res[i] = get(l);
}
return res;
}
vector<vector<vector<ll>>> slv(int l, int r){
if(l + 1 == r){
return {{{0, -inf}, {-inf, -inf}}, {{-inf, -inf}, {-inf, a[l]}}};
}
int mid = (l + r)>>1;
auto resl = slv(l, mid), resr = slv(mid, r);
int len = (r - l + 1)/2 + 1;
vector<vector<vector<ll>>> res(2, vector<vector<ll>>(2));
rep(i,0,2){
rep(j,0,2){
res[i][j] = comb(resl[i][0], resr[0][j]);
rep(t,0,2){
vector<ll> tmp = comb(resl[i][t], resr[t^1][j]);
rep(k,0,sz(tmp)) res[i][j][k] = max(res[i][j][k], tmp[k]);
}
res[i][j].resize(len);
}
}
return res;
}
int main(){ IOS();
int n; cin >> n;
rep(i,0,n) cin >> a[i];
auto res = slv(0, n);
vector<ll> ans = res[0][0];
rep(i,0,2) rep(j,0,2){
rep(k,0,sz(ans)) ans[k] = max(ans[k], res[i][j][k]);
}
rep(i,1,((n+1)>>1)+1){
cout << ans[i] << '\n';
}
return 0-0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
468 KB |
Output is correct |
2 |
Correct |
6 ms |
468 KB |
Output is correct |
3 |
Correct |
6 ms |
476 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
468 KB |
Output is correct |
6 |
Correct |
7 ms |
416 KB |
Output is correct |
7 |
Correct |
7 ms |
468 KB |
Output is correct |
8 |
Correct |
6 ms |
464 KB |
Output is correct |
9 |
Correct |
7 ms |
468 KB |
Output is correct |
10 |
Correct |
9 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
476 KB |
Output is correct |
12 |
Correct |
7 ms |
468 KB |
Output is correct |
13 |
Correct |
7 ms |
476 KB |
Output is correct |
14 |
Correct |
6 ms |
468 KB |
Output is correct |
15 |
Correct |
7 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
468 KB |
Output is correct |
17 |
Correct |
6 ms |
468 KB |
Output is correct |
18 |
Correct |
6 ms |
468 KB |
Output is correct |
19 |
Correct |
6 ms |
464 KB |
Output is correct |
20 |
Correct |
7 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
468 KB |
Output is correct |
2 |
Correct |
6 ms |
468 KB |
Output is correct |
3 |
Correct |
6 ms |
476 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
468 KB |
Output is correct |
6 |
Correct |
7 ms |
416 KB |
Output is correct |
7 |
Correct |
7 ms |
468 KB |
Output is correct |
8 |
Correct |
6 ms |
464 KB |
Output is correct |
9 |
Correct |
7 ms |
468 KB |
Output is correct |
10 |
Correct |
9 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
476 KB |
Output is correct |
12 |
Correct |
7 ms |
468 KB |
Output is correct |
13 |
Correct |
7 ms |
476 KB |
Output is correct |
14 |
Correct |
6 ms |
468 KB |
Output is correct |
15 |
Correct |
7 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
468 KB |
Output is correct |
17 |
Correct |
6 ms |
468 KB |
Output is correct |
18 |
Correct |
6 ms |
468 KB |
Output is correct |
19 |
Correct |
6 ms |
464 KB |
Output is correct |
20 |
Correct |
7 ms |
468 KB |
Output is correct |
21 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |