#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
long long max_weights(int n,int m,vector<int>x,vector<int>y,vector<int>w){
long long dp[n+2][4][4]{};
vector<pair<int,int>>hv[n+2];
vector<int>to[n+2];
for(int i = 0; i < m; i++){
hv[x[i]+2].push_back({y[i]+1,w[i]});
to[x[i]+2].push_back(y[i]);
}
for(int i = 0; i <= n+1; i++){
to[i].push_back(0);
if(i > 1){
to[i].push_back(n+3);
}
}
long long ans = 0;
for(int i = 2; i <= n+1; i++){
int sz = 0;
for(int j = 0; j < to[i-2].size(); j++){
for(int k = 0; k < to[i-1].size(); k++){
for(int v = 0; v < to[i].size(); v++){
long long now = dp[i-1][k][j];
for(auto nodes : hv[i-1]){
if(nodes.first > max(to[i-2][j],to[i-1][k])){
if(nodes.first <= to[i][v]){
now += nodes.second;
}
}
}
for(auto nodes : hv[i]){
if(nodes.first > to[i][v]){
if(nodes.first <= to[i-1][k]){
now += nodes.second;
}
}
}
dp[i][v][k] = max(dp[i][v][k],now);
ans = max(ans,now);
}
}
}
}
return ans;
}
// int main(){
// cout << max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3}) << '\n';
// }
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:24:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int j = 0; j < to[i-2].size(); j++){
| ~~^~~~~~~~~~~~~~~~
fish.cpp:25:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int k = 0; k < to[i-1].size(); k++){
| ~~^~~~~~~~~~~~~~~~
fish.cpp:26:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int v = 0; v < to[i].size(); v++){
| ~~^~~~~~~~~~~~~~
fish.cpp:23:13: warning: unused variable 'sz' [-Wunused-variable]
23 | int sz = 0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
21448 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1089 ms |
24256 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
20568 KB |
Output is correct |
2 |
Correct |
19 ms |
20568 KB |
Output is correct |
3 |
Correct |
39 ms |
21572 KB |
Output is correct |
4 |
Correct |
35 ms |
22636 KB |
Output is correct |
5 |
Correct |
78 ms |
26284 KB |
Output is correct |
6 |
Correct |
61 ms |
26204 KB |
Output is correct |
7 |
Correct |
64 ms |
26064 KB |
Output is correct |
8 |
Correct |
64 ms |
26236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
500 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
500 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
500 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
20568 KB |
Output is correct |
2 |
Correct |
19 ms |
20568 KB |
Output is correct |
3 |
Correct |
39 ms |
21572 KB |
Output is correct |
4 |
Correct |
35 ms |
22636 KB |
Output is correct |
5 |
Correct |
78 ms |
26284 KB |
Output is correct |
6 |
Correct |
61 ms |
26204 KB |
Output is correct |
7 |
Correct |
64 ms |
26064 KB |
Output is correct |
8 |
Correct |
64 ms |
26236 KB |
Output is correct |
9 |
Correct |
62 ms |
26196 KB |
Output is correct |
10 |
Correct |
60 ms |
14284 KB |
Output is correct |
11 |
Correct |
125 ms |
28616 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
26 ms |
20580 KB |
Output is correct |
19 |
Correct |
24 ms |
20572 KB |
Output is correct |
20 |
Correct |
19 ms |
20572 KB |
Output is correct |
21 |
Correct |
20 ms |
20572 KB |
Output is correct |
22 |
Correct |
80 ms |
25216 KB |
Output is correct |
23 |
Correct |
130 ms |
31944 KB |
Output is correct |
24 |
Correct |
138 ms |
32636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
21448 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |