#include "fish.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N_MAX = 1e5 + 11;
const int INC = 0;
const int DEC = 1;
const int ZERO = 2;
vector<pair<int, long long>> fish[N_MAX];
int N;
void chmax(long long& x, long long y){
x = max(x, y);
}
map<long long, long long> MSG;
long long id(int x, int y){
return ((long long) x << 32) + y;
}
long long w[5001][5001];
long long g(int x, int y){ // [x, x] times [0, y)
return w[x][y];
}
long long f(int x, int y0, int y1, int y2){ // (x - 1, y1) -> (x, y2) transition
return g(x + 1, y2) + g(x - 1, y2) - g(x, min(y1, y2)) - g(x - 1, min(y2, max(y0, y1)));
}
long long dp[3][5001][5001];
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
::N = N;
for(int i = 0; i < M; i++){
fish[X[i]].push_back({Y[i], W[i]});
}
for(int i = 0; i < N; i++){
sort(fish[i].begin(), fish[i].end());
for(int j = 1; j < fish[i].size(); j++){
fish[i][j].se += fish[i][j - 1].se;
}
for(int j = 0; j < fish[i].size(); j++){
w[i][fish[i][j].fi + 1] = fish[i][j].se;
}
for(int j = 1; j <= N; j++){
if(w[i][j] == 0) w[i][j] = w[i][j - 1];
}
}
for(int i = 0; i <= N; i++){
for(int j = 0; j <= N; j++){
dp[0][i][j] = dp[1][i][j] = dp[2][i][j] = -(1LL << 60);
}
}
dp[ZERO][0][0] = 0;
for(int x = 0; x < N; x++){
// ZERO
for(int y = 0; y <= N; y++){
chmax(dp[ZERO][x + 1][y], dp[INC][x][y]);
chmax(dp[ZERO][x + 1][y], dp[DEC][x][y]);
chmax(dp[ZERO][x + 1][0], dp[ZERO][x][y]);
}
for(int y = 0; y < N; y++){
chmax(dp[ZERO][x + 1][y + 1], dp[ZERO][x + 1][y]);
}
// INC
long long value = -(1LL << 60);
for(int y2 = 0; y2 <= N; y2++){
value = max(value, dp[INC][x][y2] - g(x, y2) - g(x - 1, y2));
chmax(dp[INC][x + 1][y2], value + g(x + 1, y2) + g(x - 1, y2));
}
value = -(1LL << 60);
for(int y2 = 0; y2 <= N; y2++){
chmax(value, dp[ZERO][x][y2] - g(x - 1, y2));
chmax(dp[INC][x + 1][y2], dp[ZERO][x][y2] - g(x - 1, y2) + g(x + 1, y2) + g(x - 1, y2));
chmax(dp[INC][x + 1][y2], value + g(x + 1, y2) + g(x - 1, y2));
}
// DEC
value = -(1LL << 60);
for(int y2 = N; y2 >= 0; y2--){
chmax(value, dp[DEC][x][y2]); chmax(value, dp[INC][x][y2]);
chmax(dp[DEC][x + 1][y2], value + g(x + 1, y2) - g(x, y2));
}
}
/*
for(int k = 0; k < 3; k++){
for(int x = 0; x <= N; x++){
for(int y = 0; y <= N; y++){
cout << dp[k][x][y] << ' ';
}
cout << endl;
}
cout << endl;
}
*/
long long ans = 0;
for(int k = 0; k < 3; k++){
for(int y = 0; y <= N; y++){
ans = max(ans, dp[k][N][y]);
}
}
return ans;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int j = 1; j < fish[i].size(); j++){
| ~~^~~~~~~~~~~~~~~~
fish.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int j = 0; j < fish[i].size(); j++){
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
489 ms |
203180 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Runtime error |
522 ms |
207716 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
521 ms |
198424 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2772 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2656 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
4 ms |
5872 KB |
Output is correct |
10 |
Correct |
7 ms |
10452 KB |
Output is correct |
11 |
Correct |
4 ms |
5856 KB |
Output is correct |
12 |
Correct |
7 ms |
10452 KB |
Output is correct |
13 |
Correct |
2 ms |
4052 KB |
Output is correct |
14 |
Correct |
7 ms |
10336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2772 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2656 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
4 ms |
5872 KB |
Output is correct |
10 |
Correct |
7 ms |
10452 KB |
Output is correct |
11 |
Correct |
4 ms |
5856 KB |
Output is correct |
12 |
Correct |
7 ms |
10452 KB |
Output is correct |
13 |
Correct |
2 ms |
4052 KB |
Output is correct |
14 |
Correct |
7 ms |
10336 KB |
Output is correct |
15 |
Correct |
6 ms |
10332 KB |
Output is correct |
16 |
Correct |
3 ms |
4180 KB |
Output is correct |
17 |
Correct |
22 ms |
13068 KB |
Output is correct |
18 |
Correct |
23 ms |
13664 KB |
Output is correct |
19 |
Correct |
21 ms |
13480 KB |
Output is correct |
20 |
Correct |
21 ms |
13564 KB |
Output is correct |
21 |
Correct |
22 ms |
13540 KB |
Output is correct |
22 |
Correct |
37 ms |
16740 KB |
Output is correct |
23 |
Correct |
9 ms |
10972 KB |
Output is correct |
24 |
Correct |
16 ms |
12208 KB |
Output is correct |
25 |
Correct |
7 ms |
10368 KB |
Output is correct |
26 |
Correct |
9 ms |
10836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2772 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2656 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
4 ms |
5872 KB |
Output is correct |
10 |
Correct |
7 ms |
10452 KB |
Output is correct |
11 |
Correct |
4 ms |
5856 KB |
Output is correct |
12 |
Correct |
7 ms |
10452 KB |
Output is correct |
13 |
Correct |
2 ms |
4052 KB |
Output is correct |
14 |
Correct |
7 ms |
10336 KB |
Output is correct |
15 |
Correct |
6 ms |
10332 KB |
Output is correct |
16 |
Correct |
3 ms |
4180 KB |
Output is correct |
17 |
Correct |
22 ms |
13068 KB |
Output is correct |
18 |
Correct |
23 ms |
13664 KB |
Output is correct |
19 |
Correct |
21 ms |
13480 KB |
Output is correct |
20 |
Correct |
21 ms |
13564 KB |
Output is correct |
21 |
Correct |
22 ms |
13540 KB |
Output is correct |
22 |
Correct |
37 ms |
16740 KB |
Output is correct |
23 |
Correct |
9 ms |
10972 KB |
Output is correct |
24 |
Correct |
16 ms |
12208 KB |
Output is correct |
25 |
Correct |
7 ms |
10368 KB |
Output is correct |
26 |
Correct |
9 ms |
10836 KB |
Output is correct |
27 |
Correct |
258 ms |
333048 KB |
Output is correct |
28 |
Correct |
94 ms |
47180 KB |
Output is correct |
29 |
Correct |
402 ms |
352744 KB |
Output is correct |
30 |
Correct |
362 ms |
352076 KB |
Output is correct |
31 |
Correct |
346 ms |
352228 KB |
Output is correct |
32 |
Correct |
120 ms |
41732 KB |
Output is correct |
33 |
Correct |
341 ms |
352264 KB |
Output is correct |
34 |
Correct |
338 ms |
352148 KB |
Output is correct |
35 |
Correct |
297 ms |
340640 KB |
Output is correct |
36 |
Correct |
376 ms |
354016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
521 ms |
198424 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
489 ms |
203180 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |