#include "fish.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=3e3+5;
ll dp[nx][nx][2], qs[nx][nx], mx;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
for (int i=0; i<M; i++) qs[X[i]+1][Y[i]+1]=W[i];
for (int i=1; i<=N; i++) for (int j=1; j<=N; j++) qs[i][j]+=qs[i][j-1];
for (int i=1; i<=N; i++)
{
vector<ll> mx1(nx), mx2(nx), mx3(nx), mx4(nx);
for (int j=0; j<=N; j++) mx1[j]=max(j>0?mx1[j-1]:LLONG_MIN, dp[i-1][j][0]-qs[i-1][j]-qs[i][j]);
for (int j=0; j<=N; j++) mx2[j]=max(j>0?mx2[j-1]:LLONG_MIN, max(dp[i-1][j][0], dp[i-1][j][1]));
if (i>=2) for (int j=N; j>=0; j--) mx3[j]=max(j<N?mx3[j+1]:LLONG_MIN, max(dp[i-2][j][0], dp[i-2][j][1])-qs[i-1][j]);
if (i>=2) for (int j=N; j>=0; j--) mx4[j]=max(j<N?mx4[j+1]:LLONG_MIN, max(dp[i-2][j][0], dp[i-2][j][1]));
for (int j=0; j<=N; j++)
{
for (int k=0; k<=j; k++) dp[i][j][0]=max(dp[i][j][0], dp[i-1][k][0]+qs[i+1][j]+qs[i-1][j]-qs[i-1][k]-qs[i][k]);
for (int k=j; k<=N; k++) dp[i][j][1]=max(dp[i][j][1], max(dp[i-1][k][1], dp[i-1][k][0])+qs[i+1][j]-qs[i][j]);
//dp[i][j][0]=max(dp[i][j][0], qs[i+1][j]+qs[i-1][j]+mx1[j]);
//dp[i][j][1]=max(dp[i][j][1], qs[i+1][j]-qs[i][j]+mx2[j]);
//if (i>=2) for (int k=0; k<=N; k++) dp[i][j][0]=max(dp[i][j][0], max(dp[i-2][k][0], dp[i-2][k][1])+qs[i+1][j]+max(0ll, qs[i-1][j]-qs[i-1][k]));
if (i>=2) for (int k=0; k<=j; k++) dp[i][j][0]=max(dp[i][j][0], qs[i+1][j]+qs[i-1][j]+mx3[j]);
if (i>=2) for (int k=j; k<=N; k++) dp[i][j][0]=max(dp[i][j][0], qs[i+1][j]+mx4[j]);
mx=max({mx, dp[i][j][0], dp[i][j][1]});
}
}
return mx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
127132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
1088 ms |
126288 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
114124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
9 ms |
2052 KB |
Output is correct |
10 |
Correct |
62 ms |
4916 KB |
Output is correct |
11 |
Correct |
11 ms |
2180 KB |
Output is correct |
12 |
Correct |
61 ms |
4864 KB |
Output is correct |
13 |
Correct |
2 ms |
1108 KB |
Output is correct |
14 |
Correct |
61 ms |
4900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
9 ms |
2052 KB |
Output is correct |
10 |
Correct |
62 ms |
4916 KB |
Output is correct |
11 |
Correct |
11 ms |
2180 KB |
Output is correct |
12 |
Correct |
61 ms |
4864 KB |
Output is correct |
13 |
Correct |
2 ms |
1108 KB |
Output is correct |
14 |
Correct |
61 ms |
4900 KB |
Output is correct |
15 |
Correct |
64 ms |
4808 KB |
Output is correct |
16 |
Correct |
3 ms |
1108 KB |
Output is correct |
17 |
Correct |
71 ms |
6228 KB |
Output is correct |
18 |
Correct |
72 ms |
6208 KB |
Output is correct |
19 |
Correct |
74 ms |
6252 KB |
Output is correct |
20 |
Correct |
71 ms |
6196 KB |
Output is correct |
21 |
Correct |
72 ms |
6148 KB |
Output is correct |
22 |
Correct |
83 ms |
7440 KB |
Output is correct |
23 |
Correct |
63 ms |
5076 KB |
Output is correct |
24 |
Correct |
71 ms |
5764 KB |
Output is correct |
25 |
Correct |
61 ms |
4848 KB |
Output is correct |
26 |
Correct |
62 ms |
5068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
9 ms |
2052 KB |
Output is correct |
10 |
Correct |
62 ms |
4916 KB |
Output is correct |
11 |
Correct |
11 ms |
2180 KB |
Output is correct |
12 |
Correct |
61 ms |
4864 KB |
Output is correct |
13 |
Correct |
2 ms |
1108 KB |
Output is correct |
14 |
Correct |
61 ms |
4900 KB |
Output is correct |
15 |
Correct |
64 ms |
4808 KB |
Output is correct |
16 |
Correct |
3 ms |
1108 KB |
Output is correct |
17 |
Correct |
71 ms |
6228 KB |
Output is correct |
18 |
Correct |
72 ms |
6208 KB |
Output is correct |
19 |
Correct |
74 ms |
6252 KB |
Output is correct |
20 |
Correct |
71 ms |
6196 KB |
Output is correct |
21 |
Correct |
72 ms |
6148 KB |
Output is correct |
22 |
Correct |
83 ms |
7440 KB |
Output is correct |
23 |
Correct |
63 ms |
5076 KB |
Output is correct |
24 |
Correct |
71 ms |
5764 KB |
Output is correct |
25 |
Correct |
61 ms |
4848 KB |
Output is correct |
26 |
Correct |
62 ms |
5068 KB |
Output is correct |
27 |
Execution timed out |
1072 ms |
73684 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
114124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
127132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |