#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<int,ll>fishies[100010];
map<int,ll>dp[100010][2];
ll ones(int col,int len){
auto it=fishies[col].upper_bound(len);
if(it==fishies[col].begin())return 0;
return (--it)->second;
}
ll max_weights(int N,int M,vector<int> X,vector<int> Y,vector<int> W) {
for(int i=0;i<M;i++)
fishies[X[i]+1][Y[i]+1]=W[i];
for(int i=1;i<=N;i++){
fishies[i][N+1];
fishies[i][1];
auto it=++fishies[i].begin();
while(it!=fishies[i].end())
it->second+=prev(it)->second,it++;
}
fishies[N+1][0];
dp[0][0][0];
dp[1][0][0];
for(int i=2;i<=N;i++){
for(auto[rw,j]:fishies[i]) {
ll K=0;
for(auto[rw2,vl]:dp[i-2][0])
K=max(K,vl+ones(i+1,rw-1)+max(0ll,ones(i-1,rw-1)-ones(i-1,rw2)));
for(auto[rw2,vl]:dp[i-2][1])
K=max(K,vl+ones(i+1,rw-1)+max(0ll,ones(i-1,rw-1)-ones(i-1,rw2)));
dp[i][1][rw-1]=K;
}
for(auto[rw,vl]:dp[i-1][0]) {
for(auto[rw2,j]:fishies[i]){
if(rw2-1>j) break;
ll K=ones(i+1,rw2-1)-ones(i,rw2-1)+vl;
dp[i][0][rw2-1]=max(dp[i][0][rw2-1],K);
}
}
for(auto[rw,vl]:dp[i-1][1]){
for(auto[rw2,j]:fishies[i]){
ll K=ones(i+1,rw2-1)-ones(i,min(rw,rw2-1))+
ones(i-1,rw2-1)-ones(i-1,min(rw2-1,rw))+vl;
dp[i][rw2>rw][rw2-1]=max(dp[i][rw2>rw][rw2-1],K);
}
}
}
ll ans=0;
for(auto[i,j]:dp[N][0])
ans=max(ans,j);
for(auto[i,j]:dp[N][1])
ans=max(ans,j);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
50996 KB |
Output is correct |
2 |
Correct |
82 ms |
55964 KB |
Output is correct |
3 |
Correct |
45 ms |
45816 KB |
Output is correct |
4 |
Correct |
38 ms |
45656 KB |
Output is correct |
5 |
Correct |
537 ms |
115700 KB |
Output is correct |
6 |
Correct |
388 ms |
118836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14428 KB |
Output is correct |
2 |
Correct |
178 ms |
69360 KB |
Output is correct |
3 |
Correct |
213 ms |
78808 KB |
Output is correct |
4 |
Correct |
70 ms |
50940 KB |
Output is correct |
5 |
Correct |
89 ms |
56040 KB |
Output is correct |
6 |
Incorrect |
2 ms |
14424 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
45648 KB |
Output is correct |
2 |
Correct |
36 ms |
45652 KB |
Output is correct |
3 |
Correct |
50 ms |
48212 KB |
Output is correct |
4 |
Correct |
51 ms |
49492 KB |
Output is correct |
5 |
Correct |
67 ms |
55892 KB |
Output is correct |
6 |
Correct |
59 ms |
48976 KB |
Output is correct |
7 |
Correct |
69 ms |
56148 KB |
Output is correct |
8 |
Correct |
67 ms |
55888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14424 KB |
Output is correct |
2 |
Correct |
2 ms |
14428 KB |
Output is correct |
3 |
Incorrect |
2 ms |
14428 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14424 KB |
Output is correct |
2 |
Correct |
2 ms |
14428 KB |
Output is correct |
3 |
Incorrect |
2 ms |
14428 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14424 KB |
Output is correct |
2 |
Correct |
2 ms |
14428 KB |
Output is correct |
3 |
Incorrect |
2 ms |
14428 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
45648 KB |
Output is correct |
2 |
Correct |
36 ms |
45652 KB |
Output is correct |
3 |
Correct |
50 ms |
48212 KB |
Output is correct |
4 |
Correct |
51 ms |
49492 KB |
Output is correct |
5 |
Correct |
67 ms |
55892 KB |
Output is correct |
6 |
Correct |
59 ms |
48976 KB |
Output is correct |
7 |
Correct |
69 ms |
56148 KB |
Output is correct |
8 |
Correct |
67 ms |
55888 KB |
Output is correct |
9 |
Correct |
97 ms |
68176 KB |
Output is correct |
10 |
Correct |
72 ms |
46644 KB |
Output is correct |
11 |
Correct |
156 ms |
78948 KB |
Output is correct |
12 |
Incorrect |
2 ms |
14424 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
50996 KB |
Output is correct |
2 |
Correct |
82 ms |
55964 KB |
Output is correct |
3 |
Correct |
45 ms |
45816 KB |
Output is correct |
4 |
Correct |
38 ms |
45656 KB |
Output is correct |
5 |
Correct |
537 ms |
115700 KB |
Output is correct |
6 |
Correct |
388 ms |
118836 KB |
Output is correct |
7 |
Correct |
2 ms |
14428 KB |
Output is correct |
8 |
Correct |
178 ms |
69360 KB |
Output is correct |
9 |
Correct |
213 ms |
78808 KB |
Output is correct |
10 |
Correct |
70 ms |
50940 KB |
Output is correct |
11 |
Correct |
89 ms |
56040 KB |
Output is correct |
12 |
Incorrect |
2 ms |
14424 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
13 |
Halted |
0 ms |
0 KB |
- |