#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 300000;
const int MAX_M = 3e5;
const long long INF = 1e18;
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 ) {
int maxY = 0;
for ( int i = 0; i < m; i++ )
maxY = max( maxY, Y[i] );
int costCell[n + 2][maxY + 1];
for ( int i = 0; i <= n + 1; i++ ) {
for ( int j = 0; j <= maxY; j++ )
costCell[i][j] = 0;
}
for ( int i = 0; i < m; i++ ) {
X[i]++;
costCell[X[i]][Y[i]] = W[i];
}
long long costTotal = 0;
for ( int y = 0; y <= maxY; y++ ) {
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 |
Execution timed out |
1176 ms |
2033968 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Execution timed out |
1060 ms |
2097152 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
14 ms |
5676 KB |
Output is correct |
4 |
Correct |
10 ms |
4700 KB |
Output is correct |
5 |
Correct |
26 ms |
7472 KB |
Output is correct |
6 |
Correct |
31 ms |
6740 KB |
Output is correct |
7 |
Correct |
26 ms |
7376 KB |
Output is correct |
8 |
Correct |
23 ms |
7360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2424 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2488 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2400 KB |
Output is correct |
9 |
Incorrect |
1 ms |
2396 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 |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2424 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2488 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2400 KB |
Output is correct |
9 |
Incorrect |
1 ms |
2396 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 |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2424 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2488 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2400 KB |
Output is correct |
9 |
Incorrect |
1 ms |
2396 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 |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
14 ms |
5676 KB |
Output is correct |
4 |
Correct |
10 ms |
4700 KB |
Output is correct |
5 |
Correct |
26 ms |
7472 KB |
Output is correct |
6 |
Correct |
31 ms |
6740 KB |
Output is correct |
7 |
Correct |
26 ms |
7376 KB |
Output is correct |
8 |
Correct |
23 ms |
7360 KB |
Output is correct |
9 |
Execution timed out |
1022 ms |
2097152 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1176 ms |
2033968 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |