#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
#define int long long
#define vel vector<int>
#define vvel vector<vel>
#define vvvel vector<vvel>
#define veb vector<bool>
void mmax(int &a, int b) { a = max(a, b); }
vel com(vel &u, vel &v) {
vel ans(1,0);
int mu = 0; int mv = 0;
int su = u.size();
int sv = v.size();
while (mu < su - 1 or mv < sv - 1) {
int nu = mu + 1;
int nv = mv + 1;
if (nu == su) { mv++; }
else if (nv == sv) { mu++; }
else if (u[nu] - u[mu] > v[nv] - v[mv]) { mu++; }
else { mv++; }
ans.push_back(u[mu] + v[mv]);
}
return ans;
}
vel r_no(int st, int to, vel &a) {
int siz = to - st;
int ko = (siz + 3) / 2;
vel bbdp(ko, -1); bbdp[0] = 0;
vel bdp = bbdp; bdp[1] = a[st];
for (int i = 2; i <= siz; i++) {
vel ndp = bdp;
for (int j = 1; j < ko; j++) {
if (bbdp[j - 1] != -1) { mmax(ndp[j], bbdp[j - 1] + a[st + i - 1]); }
}
bbdp = bdp;
bdp = ndp;
}
return bdp;
}
signed main() {
int n; cin >> n;
vel a(n);
for (int i = 0; i < n; i++) { cin >> a[i]; }
int ko = (n + 3) / 2;
if (n < 2000) {
vel x = r_no(0, n, a);
for (int i = 1; i < x.size(); i++) { cout << x[i] << endl; }
}
else {
int range = 500;
vel dp0 = r_no(0, range, a);
vel dp1 = r_no(0, range - 1, a);
int st1 = 0;
for (int i = 2; i*range <= n - range; i++) {
int st = (i - 1)*range;
int to = i * range; mmax(st1, to);
vel x0 = r_no(st, to, a);
vel x1 = r_no(st + 1, to, a);
vel qdp0 = com(dp1, x0); x0.clear();
vel rdp0 = com(dp0, x1); x1.clear();
vel y0 = r_no(st, to - 1, a);
vel y1 = r_no(st + 1, to - 1, a);
vel qdp1 = com(dp1, y0); y0.clear();
vel rdp1 = com(dp0, y1); y1.clear();
dp0 = vel(0);
for (int i = 0; i<qdp0.size() ; i++) { dp0.push_back(max(qdp0[i], rdp0[i]));}
dp1 = vel(0);
for (int i = 0; i < rdp1.size(); i++) { dp1.push_back(max(qdp1[i], rdp1[i])); }
dp1.push_back(qdp1[qdp1.size() - 1]);
}
vel x = r_no(st1, n, a);
vel y = r_no(st1 + 1, n, a);
vel qans = com(dp0, y);
vel rans = com(dp1, x);
for (int i = 1; i < ko; i++) { cout << max(qans[i], rans[i]) << endl; }
}
return 0;
}
Compilation message
candies.cpp: In function 'int main()':
candies.cpp:53:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < x.size(); i++) { cout << x[i] << endl; }
~~^~~~~~~~~~
candies.cpp:72:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i<qdp0.size() ; i++) { dp0.push_back(max(qdp0[i], rdp0[i]));}
~^~~~~~~~~~~~
candies.cpp:74:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < rdp1.size(); i++) { dp1.push_back(max(qdp1[i], rdp1[i])); }
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
384 KB |
Output is correct |
2 |
Correct |
9 ms |
384 KB |
Output is correct |
3 |
Correct |
10 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
384 KB |
Output is correct |
5 |
Correct |
9 ms |
384 KB |
Output is correct |
6 |
Correct |
9 ms |
384 KB |
Output is correct |
7 |
Correct |
8 ms |
512 KB |
Output is correct |
8 |
Correct |
7 ms |
384 KB |
Output is correct |
9 |
Correct |
10 ms |
384 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
11 |
Correct |
10 ms |
384 KB |
Output is correct |
12 |
Correct |
8 ms |
384 KB |
Output is correct |
13 |
Correct |
8 ms |
384 KB |
Output is correct |
14 |
Correct |
8 ms |
384 KB |
Output is correct |
15 |
Correct |
9 ms |
356 KB |
Output is correct |
16 |
Correct |
12 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
384 KB |
Output is correct |
18 |
Correct |
8 ms |
384 KB |
Output is correct |
19 |
Correct |
8 ms |
384 KB |
Output is correct |
20 |
Correct |
12 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
384 KB |
Output is correct |
2 |
Correct |
9 ms |
384 KB |
Output is correct |
3 |
Correct |
10 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
384 KB |
Output is correct |
5 |
Correct |
9 ms |
384 KB |
Output is correct |
6 |
Correct |
9 ms |
384 KB |
Output is correct |
7 |
Correct |
8 ms |
512 KB |
Output is correct |
8 |
Correct |
7 ms |
384 KB |
Output is correct |
9 |
Correct |
10 ms |
384 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
11 |
Correct |
10 ms |
384 KB |
Output is correct |
12 |
Correct |
8 ms |
384 KB |
Output is correct |
13 |
Correct |
8 ms |
384 KB |
Output is correct |
14 |
Correct |
8 ms |
384 KB |
Output is correct |
15 |
Correct |
9 ms |
356 KB |
Output is correct |
16 |
Correct |
12 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
384 KB |
Output is correct |
18 |
Correct |
8 ms |
384 KB |
Output is correct |
19 |
Correct |
8 ms |
384 KB |
Output is correct |
20 |
Correct |
12 ms |
384 KB |
Output is correct |
21 |
Correct |
1521 ms |
13096 KB |
Output is correct |
22 |
Correct |
1405 ms |
13200 KB |
Output is correct |
23 |
Correct |
1567 ms |
13032 KB |
Output is correct |
24 |
Correct |
1330 ms |
12912 KB |
Output is correct |
25 |
Correct |
1320 ms |
12976 KB |
Output is correct |
26 |
Correct |
1368 ms |
12956 KB |
Output is correct |
27 |
Correct |
1328 ms |
13292 KB |
Output is correct |
28 |
Correct |
1449 ms |
13200 KB |
Output is correct |
29 |
Correct |
1315 ms |
13144 KB |
Output is correct |
30 |
Correct |
1514 ms |
13284 KB |
Output is correct |
31 |
Correct |
1411 ms |
13188 KB |
Output is correct |
32 |
Correct |
1643 ms |
13224 KB |
Output is correct |
33 |
Correct |
1184 ms |
12952 KB |
Output is correct |
34 |
Correct |
1229 ms |
13128 KB |
Output is correct |
35 |
Correct |
1448 ms |
13048 KB |
Output is correct |
36 |
Correct |
1401 ms |
13152 KB |
Output is correct |
37 |
Correct |
1440 ms |
13180 KB |
Output is correct |
38 |
Correct |
1303 ms |
13156 KB |
Output is correct |
39 |
Correct |
1224 ms |
12904 KB |
Output is correct |
40 |
Correct |
1500 ms |
12928 KB |
Output is correct |
41 |
Correct |
1273 ms |
13032 KB |
Output is correct |
42 |
Correct |
1386 ms |
13164 KB |
Output is correct |
43 |
Correct |
1434 ms |
13080 KB |
Output is correct |
44 |
Correct |
1597 ms |
13016 KB |
Output is correct |
45 |
Correct |
1627 ms |
13256 KB |
Output is correct |
46 |
Correct |
1378 ms |
13312 KB |
Output is correct |
47 |
Correct |
1540 ms |
13084 KB |
Output is correct |
48 |
Correct |
1254 ms |
12908 KB |
Output is correct |
49 |
Correct |
1520 ms |
12820 KB |
Output is correct |
50 |
Correct |
1570 ms |
12896 KB |
Output is correct |