#include "fish.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
map<pair<int,int>, int> a;
vector<vector<int>> fsh;
map<pair<int,pair<int,int>>, int> memo;
int N,M;
int dp(int x, int last, int lastlast){
if(memo.find({x,{last,lastlast}})!=memo.end()) return memo[{x,{last,lastlast}}];
if(x==N) return 0;
memo[{x,{last,lastlast}}] = 0;
for (auto i:fsh[x])
{
int c=dp(x+1, i, last);
for (int j=0; j<fsh[x].size(); j++) {
if(fsh[x][j]<=max(i,lastlast)&&fsh[x][j]>last) {
c+=a[{x-1,fsh[x][j]-1}];
}
}
if(x==N-1) {
for (int j=0; j<fsh[N].size(); j++) {
if(fsh[N][j]<=last&&fsh[N][j]>i) {
c+=a[{x,fsh[N][j]-1}];
}
}
}
memo[{x,{last,lastlast}}]=max(c, memo[{x,{last,lastlast}}]);
}
return memo[{x,{last,lastlast}}];
}
long long max_weights(signed n, signed m, std::vector<signed> X, std::vector<signed> Y, std::vector<signed> W) {
N=n; M=m;
fsh.resize(N+1, vector<int>(1,0));
for (int i = 0; i < M; i++){
a[{X[i],Y[i]}] = W[i];
fsh[X[i]+1].push_back(Y[i]+1);
if(X[i]>0) fsh[X[i]-1].push_back(Y[i]+1);
}
int p=dp(0,0,0);
return p;
}
Compilation message
fish.cpp: In function 'long long int dp(long long int, long long int, long long int)':
fish.cpp:18:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (int j=0; j<fsh[x].size(); j++) {
| ~^~~~~~~~~~~~~~
fish.cpp:24:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int j=0; j<fsh[N].size(); j++) {
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1034 ms |
38084 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1057 ms |
46736 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
33872 KB |
Output is correct |
2 |
Correct |
67 ms |
33872 KB |
Output is correct |
3 |
Incorrect |
308 ms |
50332 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '40569366478878' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 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 |
Incorrect |
9 ms |
604 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '431415511050' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 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 |
Incorrect |
9 ms |
604 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '431415511050' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 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 |
Incorrect |
9 ms |
604 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '431415511050' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
33872 KB |
Output is correct |
2 |
Correct |
67 ms |
33872 KB |
Output is correct |
3 |
Incorrect |
308 ms |
50332 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '40569366478878' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1034 ms |
38084 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |