#include "fish.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
map<pair<int,int>, int> a;
vector<vector<int>> fsh;
vector<vector<int>> cfsh;
int allPOSS=0;
map<pair<int,pair<int,int>>, int> memo;
int N,M;
int dp(int x, int last, int big){
if(memo[{x,{last,big}}]!=0) {
return memo[{x,{last,big}}]-1;
}
if(x==N) return 0;
memo[{x,{last,big}}] = 0;
for (auto i:fsh[x])
{
int c=0;
int bg=0;
if(i>=last){
c=dp(x+1, i, 1);
bg=1;
if(!big) continue;
}else {
c=dp(x+1, i, 0);
bg=0;
}
if(x>0){
if(bg) {
for (auto y:cfsh[x-1]) {
if(y>last&&y<=i) c+=a[{x-1,y-1}];
}
} else{
for (auto y:cfsh[x]) {
if(y>i&&y<=last) c+=a[{x,y-1}];
}
}
}
memo[{x,{last,big}}]=max(c, memo[{x,{last,big}}]);
}
memo[{x,{last,big}}]+=1;
return memo[{x,{last,big}}]-1;
}
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));
cfsh.resize(N+1);
for (int i = 0; i < M; i++){
a[{X[i],Y[i]}] = W[i];
fsh[X[i]+1].push_back(Y[i]+1);
cfsh[X[i]].push_back(Y[i]+1);
if(X[i]>0) {
fsh[X[i]-1].push_back(Y[i]+1);
}
}
int p=dp(0,0,1);
return p;
}
/*
10 4
0 2 5
0 4 3
1 1 2
1 1 8
2 2 5
2 4 3
3 3 3
3 4 3
4 4 1
4 2 10
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1033 ms |
41064 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
1064 ms |
49980 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
36420 KB |
Output is correct |
2 |
Correct |
77 ms |
36180 KB |
Output is correct |
3 |
Incorrect |
241 ms |
49064 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '1999703533' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
344 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 |
3 ms |
800 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '7581483960' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
344 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 |
3 ms |
800 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '7581483960' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
344 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 |
3 ms |
800 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '7581483960' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
36420 KB |
Output is correct |
2 |
Correct |
77 ms |
36180 KB |
Output is correct |
3 |
Incorrect |
241 ms |
49064 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '1999703533' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1033 ms |
41064 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |