#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){
return (--fishies[col].upper_bound(len))->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];
for(auto[i,j]:fishies[1])
dp[1][1][i-1]=ones(2,i-1);
dp[0][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))+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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
56088 KB |
Output is correct |
2 |
Correct |
108 ms |
62256 KB |
Output is correct |
3 |
Incorrect |
41 ms |
45648 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '0' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
14428 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
45652 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
14524 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
14524 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
14524 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
45652 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
56088 KB |
Output is correct |
2 |
Correct |
108 ms |
62256 KB |
Output is correct |
3 |
Incorrect |
41 ms |
45648 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '0' |
4 |
Halted |
0 ms |
0 KB |
- |