#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll pref[3005][3005], dp[3005][3005][2], pmx1[3005][3005], smx1[3005][3005], pmx2[3005][3005];
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
for(int i=0; i<M; i++) pref[X[i]+1][Y[i]+1] += W[i];
for(int i=1; i<=N; i++)
for(int j=1; j<=N; j++) pref[i][j] += pref[i][j-1];
for(int i=1; i<=N; i++)
for(int j=0; j<=N; j++) pmx1[i][j] = smx1[i][j] = pmx2[i][j] = -1e18;
pmx1[1][0] = dp[1][0][1] - pref[1][0];
smx1[1][N] = max(dp[1][N][0], dp[1][N][1]) + pref[2][N];
for(int i=1; i<=N; i++) pmx1[1][i] = max(pmx1[1][i-1], dp[1][i][1] - pref[1][i]);
for(int i=N-1; i>=0; i--) smx1[1][i] = max(smx1[1][i+1], max(dp[1][i][0], dp[1][i][1]) + pref[2][i]);
for(int i=1; i<=N; i++) pmx2[1][i] = max(pmx2[1][i-1], max(dp[1][i][0], dp[1][i][1]));
for(int i=2; i<=N; i++) {
for(int j=0; j<=N; j++) {
dp[i][j][0] = max(dp[i][j][0], smx1[i-1][j] - pref[i][j]);
dp[i][j][1] = max({ dp[i][j][1], pmx1[i-1][j] + pref[i-1][j] });
if(i >= 3) dp[i][j][0] = max(dp[i][j][0], pmx2[i-2][j] + pref[i-1][j]);
if(i >= 3) dp[i][j][1] = max(dp[i][j][1], pmx2[i-2][j] + pref[i-1][j]);
for(int k=0; k<=N; k++) {
if(i >= 3) dp[i][j][1] = max(dp[i][j][1], max(dp[i-2][k][0], dp[i-2][k][1]) + max(pref[i-1][j], pref[i-1][k]));
}
if(j) pmx1[i][j] = pmx1[i][j-1];
if(j) pmx2[i][j] = pmx2[i][j-1];
pmx1[i][j] = max(pmx1[i][j], dp[i][j][1] - pref[i][j]);
pmx2[i][j] = max(pmx2[i][j], max(dp[i][j][0], dp[i][j][1]));
}
smx1[i][N] = max(dp[i][N][0], dp[i][N][1]) + pref[i+1][N];
for(int j=N-1; j>=0; j--) smx1[i][j] = max(smx1[i][j+1], max(dp[i][j][0], dp[i][j][1]) + pref[i+1][j]);
}
ll ans = 0;
for(int i=1; i<=N; i++)
for(int j=1; j<=N; j++) ans = max({ ans, dp[i][j][0] + pref[i+1][j], dp[i][j][1] + pref[i+1][j] });
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
174 ms |
148144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Runtime error |
185 ms |
152172 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
163 ms |
144348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
8700 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
6 ms |
21852 KB |
Output is correct |
10 |
Correct |
30 ms |
37976 KB |
Output is correct |
11 |
Correct |
6 ms |
21852 KB |
Output is correct |
12 |
Correct |
28 ms |
37840 KB |
Output is correct |
13 |
Correct |
2 ms |
15192 KB |
Output is correct |
14 |
Correct |
28 ms |
37844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
8700 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
6 ms |
21852 KB |
Output is correct |
10 |
Correct |
30 ms |
37976 KB |
Output is correct |
11 |
Correct |
6 ms |
21852 KB |
Output is correct |
12 |
Correct |
28 ms |
37840 KB |
Output is correct |
13 |
Correct |
2 ms |
15192 KB |
Output is correct |
14 |
Correct |
28 ms |
37844 KB |
Output is correct |
15 |
Correct |
28 ms |
37968 KB |
Output is correct |
16 |
Correct |
2 ms |
15192 KB |
Output is correct |
17 |
Correct |
38 ms |
38872 KB |
Output is correct |
18 |
Correct |
40 ms |
39020 KB |
Output is correct |
19 |
Correct |
35 ms |
38992 KB |
Output is correct |
20 |
Correct |
41 ms |
38904 KB |
Output is correct |
21 |
Correct |
35 ms |
38888 KB |
Output is correct |
22 |
Correct |
41 ms |
39988 KB |
Output is correct |
23 |
Correct |
30 ms |
37976 KB |
Output is correct |
24 |
Correct |
33 ms |
38480 KB |
Output is correct |
25 |
Correct |
30 ms |
38024 KB |
Output is correct |
26 |
Correct |
30 ms |
37968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
8700 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
6 ms |
21852 KB |
Output is correct |
10 |
Correct |
30 ms |
37976 KB |
Output is correct |
11 |
Correct |
6 ms |
21852 KB |
Output is correct |
12 |
Correct |
28 ms |
37840 KB |
Output is correct |
13 |
Correct |
2 ms |
15192 KB |
Output is correct |
14 |
Correct |
28 ms |
37844 KB |
Output is correct |
15 |
Correct |
28 ms |
37968 KB |
Output is correct |
16 |
Correct |
2 ms |
15192 KB |
Output is correct |
17 |
Correct |
38 ms |
38872 KB |
Output is correct |
18 |
Correct |
40 ms |
39020 KB |
Output is correct |
19 |
Correct |
35 ms |
38992 KB |
Output is correct |
20 |
Correct |
41 ms |
38904 KB |
Output is correct |
21 |
Correct |
35 ms |
38888 KB |
Output is correct |
22 |
Correct |
41 ms |
39988 KB |
Output is correct |
23 |
Correct |
30 ms |
37976 KB |
Output is correct |
24 |
Correct |
33 ms |
38480 KB |
Output is correct |
25 |
Correct |
30 ms |
38024 KB |
Output is correct |
26 |
Correct |
30 ms |
37968 KB |
Output is correct |
27 |
Execution timed out |
1063 ms |
288848 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
163 ms |
144348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
174 ms |
148144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |