#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> a;
vector<vector<int>> fsh;
vector<vector<int>> prefx;
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 memo[{x,{last,lastlast}}]=0;
memo[{x,{last,lastlast}}] = 0;
for (auto i:fsh[x])
{
int c=dp(x+1, i, last);
if(x>0) c+=max(0,prefx[x-1][max(i,lastlast)]-prefx[x-1][last]);
if(x==N-1) c+=max(0,prefx[x][last]-prefx[x][i]);
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;
a.resize(N, vector<int>(N,0));
fsh.resize(N+1, vector<int>(1,0));
prefx.resize(N, vector<int>(N+1,0)); //y+1
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);
}
for (int x = 0; x < N; x++)
{
for (int y = 0; y < N; y++)
{
prefx[x][y+1]=a[x][y]+prefx[x][y];
}
}
int p=dp(0,0,0);
return p;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
963 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
790 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
789 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
7 ms |
860 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '2146156479' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
7 ms |
860 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '2146156479' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
7 ms |
860 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '2146156479' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
789 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
963 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |