#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
ll max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W){
vector<vector<ll>> v(n, vector<ll>(n+1, 0));
for(int i = 0; i < m; i++) v[X[i]][Y[i]+1]+=W[i];
vector<vector<ll>> dp_up(n, vector<ll>(n+1, 0)), dp_down = dp_up,
dtu2 = dp_up;
vector<ll> dtu(n, 0);
vector<vector<ll>> pref(n, vector<ll>(n+1, 0));
for(int i = 0; i < n; i++) for(int j = 0; j <= n; j++){
if(j) pref[i][j] = pref[i][j-1];
pref[i][j]+=v[i][j];
}
for(int i = n-1; i >= 0; i--){
for(int j = 0; j <= n; j++){
if(i == n-1){
dp_down[i][j] = 0;
dp_up[i][j] = 0;
continue;
}
dp_up[i][j]-=pref[i][j];
dp_down[i][j]-=pref[i+1][n]-pref[i+1][j];
dp_up[i][j] = max(dp_up[i][j], pref[i][n]-pref[i][j]+dp_down[i+1][n]);
if(i+2 < n){
dp_down[i][j] = max(dp_down[i][j], dtu2[i+2][j]+pref[i+1][j]);
dp_down[i][j] = max(dp_down[i][j], dtu[i+2]-pref[i+1][j]);
dp_down[i][j] = max(dp_down[i][j], pref[i+1][n]+dp_down[i+2][n]);
}
}
if(i){
ll mx = 0;
for(int j = 0; j <= n; j++) mx = max(mx, pref[i-1][j]+dp_up[i][j]);
fill(dp_up[i-1].begin(), dp_up[i-1].end(), mx);
dtu[i] = mx;
mx = 0;
for(int j = 0; j <= n; j++) mx = max(mx, pref[i][n]-pref[i][j]+dp_down[i][j]);
fill(dp_down[i-1].begin(), dp_down[i-1].end(), mx);
for(int j = 0; j <= n; j++){
if(j) dtu2[i][j] = dtu2[i][j-1];
dtu2[i][j] = max(dtu2[i][j], dp_up[i][j]);
}
}
}
return max(*max_element(dp_up[0].begin(), dp_up[0].end()), *max_element(dp_down[0].begin(), dp_down[0].end()));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
740 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
749 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
712 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
252 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
4 ms |
3924 KB |
Output is correct |
11 |
Correct |
2 ms |
1236 KB |
Output is correct |
12 |
Correct |
4 ms |
3796 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
3796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
252 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
4 ms |
3924 KB |
Output is correct |
11 |
Correct |
2 ms |
1236 KB |
Output is correct |
12 |
Correct |
4 ms |
3796 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
3796 KB |
Output is correct |
15 |
Correct |
3 ms |
3880 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
20 ms |
5628 KB |
Output is correct |
18 |
Correct |
21 ms |
5636 KB |
Output is correct |
19 |
Correct |
15 ms |
5580 KB |
Output is correct |
20 |
Correct |
16 ms |
5592 KB |
Output is correct |
21 |
Correct |
16 ms |
5492 KB |
Output is correct |
22 |
Correct |
29 ms |
6628 KB |
Output is correct |
23 |
Correct |
6 ms |
4180 KB |
Output is correct |
24 |
Correct |
11 ms |
4972 KB |
Output is correct |
25 |
Correct |
4 ms |
3924 KB |
Output is correct |
26 |
Correct |
7 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
252 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
4 ms |
3924 KB |
Output is correct |
11 |
Correct |
2 ms |
1236 KB |
Output is correct |
12 |
Correct |
4 ms |
3796 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
3796 KB |
Output is correct |
15 |
Correct |
3 ms |
3880 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
20 ms |
5628 KB |
Output is correct |
18 |
Correct |
21 ms |
5636 KB |
Output is correct |
19 |
Correct |
15 ms |
5580 KB |
Output is correct |
20 |
Correct |
16 ms |
5592 KB |
Output is correct |
21 |
Correct |
16 ms |
5492 KB |
Output is correct |
22 |
Correct |
29 ms |
6628 KB |
Output is correct |
23 |
Correct |
6 ms |
4180 KB |
Output is correct |
24 |
Correct |
11 ms |
4972 KB |
Output is correct |
25 |
Correct |
4 ms |
3924 KB |
Output is correct |
26 |
Correct |
7 ms |
4180 KB |
Output is correct |
27 |
Correct |
286 ms |
353264 KB |
Output is correct |
28 |
Correct |
75 ms |
31232 KB |
Output is correct |
29 |
Correct |
414 ms |
365772 KB |
Output is correct |
30 |
Correct |
377 ms |
365772 KB |
Output is correct |
31 |
Correct |
414 ms |
365844 KB |
Output is correct |
32 |
Correct |
90 ms |
24272 KB |
Output is correct |
33 |
Correct |
425 ms |
365832 KB |
Output is correct |
34 |
Correct |
396 ms |
366048 KB |
Output is correct |
35 |
Correct |
349 ms |
357928 KB |
Output is correct |
36 |
Correct |
367 ms |
365656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
712 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
740 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |