#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3002;
const int MAX_M = 3e5;
const long long INF = 1e18;
int costCell[MAX_N][MAX_N];
long long dp[MAX_N][MAX_N], dpLower[MAX_N][MAX_N], spX[MAX_N][MAX_N];
vector<int> possibleY[MAX_N];
long long max_weights( int n, int m, vector <int> X, vector <int> Y, vector <int> W ) {
for ( int i = 0; i < m; i++ ) {
X[i]++;
Y[i]++;
costCell[X[i]][Y[i]] = W[i];
}
for ( int x = 1; x <= n; x++ ) {
for ( int y = 1; y <= n; y++ ) {
//if ( costCell[x][y] ) {
possibleY[x].push_back( y - 1 );
possibleY[x - 1].push_back( y );
possibleY[x + 1].push_back( y );
//}
}
}
possibleY[0].clear();
possibleY[n + 1].clear();
for ( int x = 0; x <= n + 1; x++ )
possibleY[x].push_back( 0 );
for ( int x = 1; x <= n; x++ ) {
sort( possibleY[x].begin(), possibleY[x].end() );
possibleY[x].resize( unique( possibleY[x].begin(), possibleY[x].end() ) - possibleY[x].begin() );
}
for ( int x = 1; x <= n; x++ ) {
for ( int y = 1; y <= n; y++ )
spX[x][y] = spX[x][y - 1] + costCell[x][y];
}
for ( int crtY = 1; crtY <= n; crtY++ )
dp[0][crtY] = dpLower[0][crtY] = -INF;
dp[0][0] = dpLower[0][0] = 0;
for ( int x = 1; x <= n + 1; x++ ) {
for ( int crtY: possibleY[x] ) {
dp[x][crtY] = dpLower[x][crtY] = -INF;
for ( int prevY: possibleY[x - 1] ) {
if ( prevY <= crtY ) {
dpLower[x][crtY] = max( dpLower[x][crtY], dpLower[x - 1][prevY] + spX[x - 1][crtY] - spX[x - 1][prevY] );
if ( x >= 2 )
dpLower[x][crtY] = max( dpLower[x][crtY], dp[x - 2][prevY] + spX[x - 1][crtY] );
dp[x][crtY] = max( dp[x][crtY], dpLower[x - 1][prevY] + spX[x - 1][crtY] - spX[x - 1][prevY] );
if ( x >= 2 )
dp[x][crtY] = max( dp[x][crtY], dp[x - 2][prevY] + spX[x - 1][crtY] );
}
if ( prevY >= crtY ) {
if ( x >= 2 )
dpLower[x][crtY] = max( dpLower[x][crtY], dp[x - 2][prevY] + spX[x - 1][prevY] );
dp[x][crtY] = max( dp[x][crtY], dp[x - 1][prevY] + spX[x][prevY] - spX[x][crtY] );
if ( x >= 2 )
dp[x][crtY] = max( dp[x][crtY], dp[x - 2][prevY] + spX[x - 1][prevY] );
}
}
//printf( "(%d %lld) ", crtY, dpLower[x][crtY] );
}
//printf( "\n" );
}
return dp[n + 1][0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1139 ms |
1510784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Execution timed out |
1146 ms |
1698092 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1156 ms |
1855932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 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 |
6504 KB |
Output is correct |
6 |
Correct |
1 ms |
6500 KB |
Output is correct |
7 |
Correct |
1 ms |
6504 KB |
Output is correct |
8 |
Correct |
1 ms |
6500 KB |
Output is correct |
9 |
Correct |
15 ms |
16000 KB |
Output is correct |
10 |
Correct |
100 ms |
27776 KB |
Output is correct |
11 |
Correct |
15 ms |
15972 KB |
Output is correct |
12 |
Correct |
100 ms |
27728 KB |
Output is correct |
13 |
Correct |
3 ms |
11100 KB |
Output is correct |
14 |
Correct |
108 ms |
27732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 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 |
6504 KB |
Output is correct |
6 |
Correct |
1 ms |
6500 KB |
Output is correct |
7 |
Correct |
1 ms |
6504 KB |
Output is correct |
8 |
Correct |
1 ms |
6500 KB |
Output is correct |
9 |
Correct |
15 ms |
16000 KB |
Output is correct |
10 |
Correct |
100 ms |
27776 KB |
Output is correct |
11 |
Correct |
15 ms |
15972 KB |
Output is correct |
12 |
Correct |
100 ms |
27728 KB |
Output is correct |
13 |
Correct |
3 ms |
11100 KB |
Output is correct |
14 |
Correct |
108 ms |
27732 KB |
Output is correct |
15 |
Correct |
107 ms |
27692 KB |
Output is correct |
16 |
Correct |
4 ms |
11108 KB |
Output is correct |
17 |
Correct |
113 ms |
29528 KB |
Output is correct |
18 |
Correct |
110 ms |
29276 KB |
Output is correct |
19 |
Correct |
112 ms |
29492 KB |
Output is correct |
20 |
Correct |
108 ms |
29492 KB |
Output is correct |
21 |
Correct |
109 ms |
29264 KB |
Output is correct |
22 |
Correct |
124 ms |
31320 KB |
Output is correct |
23 |
Correct |
103 ms |
27988 KB |
Output is correct |
24 |
Correct |
126 ms |
28880 KB |
Output is correct |
25 |
Correct |
99 ms |
27720 KB |
Output is correct |
26 |
Correct |
104 ms |
27992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 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 |
6504 KB |
Output is correct |
6 |
Correct |
1 ms |
6500 KB |
Output is correct |
7 |
Correct |
1 ms |
6504 KB |
Output is correct |
8 |
Correct |
1 ms |
6500 KB |
Output is correct |
9 |
Correct |
15 ms |
16000 KB |
Output is correct |
10 |
Correct |
100 ms |
27776 KB |
Output is correct |
11 |
Correct |
15 ms |
15972 KB |
Output is correct |
12 |
Correct |
100 ms |
27728 KB |
Output is correct |
13 |
Correct |
3 ms |
11100 KB |
Output is correct |
14 |
Correct |
108 ms |
27732 KB |
Output is correct |
15 |
Correct |
107 ms |
27692 KB |
Output is correct |
16 |
Correct |
4 ms |
11108 KB |
Output is correct |
17 |
Correct |
113 ms |
29528 KB |
Output is correct |
18 |
Correct |
110 ms |
29276 KB |
Output is correct |
19 |
Correct |
112 ms |
29492 KB |
Output is correct |
20 |
Correct |
108 ms |
29492 KB |
Output is correct |
21 |
Correct |
109 ms |
29264 KB |
Output is correct |
22 |
Correct |
124 ms |
31320 KB |
Output is correct |
23 |
Correct |
103 ms |
27988 KB |
Output is correct |
24 |
Correct |
126 ms |
28880 KB |
Output is correct |
25 |
Correct |
99 ms |
27720 KB |
Output is correct |
26 |
Correct |
104 ms |
27992 KB |
Output is correct |
27 |
Execution timed out |
1067 ms |
227516 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1156 ms |
1855932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1139 ms |
1510784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |