#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;
vector<pii> fish[N_MAX];
int N;
long long g(int x, int y){ // [x, x] times [0, y)
if(x < 0 || x >= N) return 0;
auto ptr = lower_bound(fish[x].begin(), fish[x].end(), pair<int, int>{y, -1});
if(ptr == fish[x].begin()) return 0;
return (--ptr)->se;
}
long long f(int x, int y0, int y1, int y2){ // (x - 1, y1) -> (x, y2) transition
if(y1 >= y2){
return g(x + 1, y2) - g(x, y2);
}else{
return g(x + 1, y2) - g(x, y1) + g(x - 1, y2) - g(x - 1, max(y0, y1));
}
}
long long dp[501][501][501];
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 i = 0; i <= N; i++){
for(int j = 0; j <= 10; j++){
for(int k = 0; k <= 10; k++){
dp[i][j][k] = -(1LL << 60);
}
}
}
dp[0][0][0] = 0;
for(int x = 0; x < N; x++){
for(int y1 = 0; y1 <= 10; y1++){
for(int y2 = 0; y2 <= 10; y2++){
for(int y3 = 0; y3 <= 10; y3++){
dp[x + 1][y2][y3] = max(dp[x + 1][y2][y3], dp[x][y1][y2] + f(x, y1, y2, y3));
}
}
}
}
long long ans = 0;
for(int y1 = 0; y1 <= 10; y1++){
for(int y2 = 0; y2 <= 10; y2++){
ans = max(ans, dp[N][y1][y2]);
}
}
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:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int j = 1; j < fish[i].size(); j++){
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
60 ms |
40656 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2772 KB |
Output is correct |
2 |
Runtime error |
90 ms |
43232 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
36 ms |
38068 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2772 KB |
Output is correct |
2 |
Correct |
2 ms |
3028 KB |
Output is correct |
3 |
Correct |
2 ms |
2772 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
1 ms |
2772 KB |
Output is correct |
9 |
Incorrect |
8 ms |
9780 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '142412077026' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2772 KB |
Output is correct |
2 |
Correct |
2 ms |
3028 KB |
Output is correct |
3 |
Correct |
2 ms |
2772 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
1 ms |
2772 KB |
Output is correct |
9 |
Incorrect |
8 ms |
9780 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '142412077026' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2772 KB |
Output is correct |
2 |
Correct |
2 ms |
3028 KB |
Output is correct |
3 |
Correct |
2 ms |
2772 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
1 ms |
2772 KB |
Output is correct |
9 |
Incorrect |
8 ms |
9780 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '142412077026' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
36 ms |
38068 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
60 ms |
40656 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |