#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
struct cf {
int x, y, w;
};
const int MAX_N = 3002;
const int MAX_M = 3e5;
const long long INF = 1e18;
cf catfish[MAX_M];
//vector<int> line[MAX_N];
int costCell[MAX_N][MAX_N];
long long dp[MAX_N][2], costCol[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]++;
catfish[i] = { X[i], Y[i], W[i] };
//line[catfish[i].y].push_back( i );
costCell[X[i]][Y[i]] = W[i];
}
long long costTotal = 0;
for ( int y = 0; y < n; y++ ) {
/*sort( line[l].begin(), line[l].end(), []( int i, int j ) {
return catfish[i].x < catfish[j].x;
} );*/
dp[0][0] = 0;
dp[0][1] = -INF;
for ( int x = 1; x <= n + 1; x++ ) {
dp[x][0] = dp[x][1] = -INF;
dp[x][0] = max( dp[x][0], dp[x - 1][0] );
dp[x][0] = max( dp[x][0], dp[x - 1][1] + costCell[x][y] );
dp[x][1] = max( dp[x][1], dp[x - 1][0] - costCol[x] );
dp[x][1] = max( dp[x][1], dp[x - 1][1] - costCol[x] );
if ( x >= 2 ) {
dp[x][1] = max( dp[x][1], dp[x - 2][0] + costCell[x - 1][y] - costCol[x] );
dp[x][1] = max( dp[x][1], dp[x - 2][1] + costCell[x - 1][y] - costCol[x] );
}
}
costTotal += dp[n + 1][0];
int side = 0, x = n + 1;
while ( x > 0 ) {
if ( side == 0 ) {
if ( dp[x][0] == dp[x - 1][0] ) {
x--;
side = 0;
} else if ( dp[x][0] == dp[x - 1][1] + costCell[x][y] ) {
costCol[x] += costCell[x][y];
x--;
side = 1;
}
} else {
if ( dp[x][1] == dp[x - 1][0] - costCol[x] ) {
costCol[x] = 0;
x--;
side = 0;
} else if ( dp[x][1] == dp[x - 1][1] - costCol[x] ) {
costCol[x] = 0;
x--;
side = 1;
} else if ( dp[x][1] == dp[x - 2][0] + costCell[x - 1][y] - costCol[x] ) {
costCol[x] = 0;
costCol[x - 1] += costCell[x - 1][y];
x -= 2;
side = 0;
} else if ( dp[x][1] == dp[x - 2][1] + costCell[x - 1][y] - costCol[x] ) {
costCol[x] = 0;
costCol[x - 1] += costCell[x - 1][y];
x -= 2;
side = 1;
}
}
}
/*printf( "%d: \n", y );
printf( "costTotal %d\n", costTotal );
for ( int x = 1; x <= n; x++ )
printf( "%d ", costCol[x] );
printf( "\n" );
for ( int c = 1; c <= n; c++ )
printf( "(%d %d) ", dp[c][0], dp[c][1] );
printf( "\n\n" );*/
}
return costTotal;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
24 ms |
13908 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Runtime error |
43 ms |
18724 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
4696 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2492 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Incorrect |
1 ms |
4444 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '201346852845' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2492 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Incorrect |
1 ms |
4444 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '201346852845' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2492 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Incorrect |
1 ms |
4444 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '201346852845' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
4696 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
24 ms |
13908 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |