#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define all(x) begin(x),end(x)
ll solve(ll&n,ll&m,vll&x,vll&y,vll&w)
{
ll ans=0;
ll val[n+1][n+1],pre[n+1][n+1];
for(int i=0;i<n;i++)for(int j=0;j<=n;j++)val[i][j]=pre[i][j]=0;
for(int j=0;j<m;j++)val[x[j]][y[j]+1]+=w[j];
for(int i=0;i<=n;i++)
{
pre[i][0]=val[i][0];
for(int j=1;j<=n;j++)
pre[i][j]=pre[i][j-1]+val[i][j];
}
ll dp[n+1][n+1][3];
for(int i=0;i<n;i++)
for(int j=0;j<=n;j++)
for(int k=0;k<2;k++)
dp[i][j][k]=0;
for(int i=1;i<n;i++)
{
// ll sum=0;
for(int h=0;h<=n;h++)
{
for(int hp=0;hp<=n;hp++)
{
dp[i][h][0]=max(dp[i][h][0],dp[i-1][hp][0]);
dp[i][h][0]=max(dp[i][h][0],dp[i-1][hp][1]);
dp[i][h][0]=max(dp[i][h][0],dp[i-1][hp][0]-pre[i-1][hp]+pre[i][h]);
}
for(int hp=0;hp<=n;hp++)
{
dp[i][h][1]=max(dp[i][h][1],dp[i-1][hp][0]);
dp[i][h][1]=max(dp[i][h][1],dp[i-1][hp][1]);
dp[i][h][1]=max(dp[i][h][1],dp[i-1][hp][0]+pre[i-1][h]-pre[i-1][hp]);
dp[i][h][1]=max(dp[i][h][1],dp[i-1][hp][1]+pre[i][hp]-pre[i][h]);
}
// sum+=val[i-1][h];
// ll aux=0;
// for(int nh=h+1;nh<=n;nh++)
// {
// aux+=val[i][nh];
// dp[i][h][0]=max(dp[i][h][0],dp[i-1][nh][0]);
// dp[i][h][0]=max(dp[i][h][0],dp[i-1][nh][1]);
// dp[i][h][1]=max(dp[i][h][1],dp[i-1][nh][0]);
// dp[i][h][1]=max(dp[i][h][1],dp[i-1][nh][1]+aux);
// }
// ll og=sum;
// for(int nh=0;nh<=h;nh++)
// {
// sum-=val[i-1][nh];
// dp[i][h][0]=max(dp[i][h][0],dp[i-1][nh][0]+sum);
// dp[i][h][0]=max(dp[i][h][0],dp[i-1][nh][1]);
// dp[i][h][1]=max(dp[i][h][1],dp[i-1][nh][0]+sum);
// dp[i][h][1]=max(dp[i][h][1],dp[i-1][nh][1]);
// }
// sum=og;
}
}
for(int i=0;i<n;i++)
{
for(int h=0;h<=n;h++)
{
cout<<"For: "<<i<<' '<<h<<' '<<dp[i][h][0]<<' '<<dp[i][h][1]<<endl;
ans=max(ans,dp[i][h][0]);
ans=max(ans,dp[i][h][1]);
}
}
return ans;
}
ll subtask3(ll&n,ll&m,vll&x,vll&y,vll&w)
{
ll ans=0;
ll val[n+1];
for(int i=0;i<n;i++)val[i]=0;
for(int j=0;j<m;j++)val[x[j]]+=w[j];
ll dp[n+1][3][3];
for(int i=0;i<n;i++)
for(int j=0;j<2;j++)
for(int k=0;k<2;k++)
dp[i][j][k]=0;
for(int i=1;i<n;i++)
{
// wall not at i
dp[i][0][0]=max(max(dp[i-1][0][0],dp[i-1][0][1]),dp[i-1][1][0]);
dp[i][0][1]=max(max(dp[i-1][0][0],dp[i-1][0][1]),dp[i-1][1][0]+val[i]);
dp[i][1][0]=max(max(dp[i-1][0][1],dp[i-1][0][0]+val[i-1]),dp[i-1][1][0]);
}
for(int i=0;i<n;i++)
{
ans=max({ans,dp[i][0][0],dp[i][0][1],dp[i][1][0],dp[i][1][1]});
}
return ans;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W)
{
ll n=N,m=M,ans=0;
vector<ll> x(all(X)),y(all(Y)),w(all(W));
if(n<=300)
return solve(n,m,x,y,w);
return subtask3(n,m,x,y,w);
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:106:16: warning: unused variable 'ans' [-Wunused-variable]
106 | ll n=N,m=M,ans=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
12628 KB |
Output is correct |
2 |
Correct |
22 ms |
14456 KB |
Output is correct |
3 |
Correct |
4 ms |
8028 KB |
Output is correct |
4 |
Correct |
5 ms |
8028 KB |
Output is correct |
5 |
Correct |
63 ms |
28504 KB |
Output is correct |
6 |
Correct |
70 ms |
28888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Possible tampering with the output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8108 KB |
Output is correct |
2 |
Correct |
6 ms |
8028 KB |
Output is correct |
3 |
Correct |
15 ms |
10840 KB |
Output is correct |
4 |
Correct |
11 ms |
10608 KB |
Output is correct |
5 |
Correct |
24 ms |
14388 KB |
Output is correct |
6 |
Correct |
23 ms |
13756 KB |
Output is correct |
7 |
Correct |
27 ms |
14424 KB |
Output is correct |
8 |
Correct |
22 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Possible tampering with the output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Possible tampering with the output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Possible tampering with the output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8108 KB |
Output is correct |
2 |
Correct |
6 ms |
8028 KB |
Output is correct |
3 |
Correct |
15 ms |
10840 KB |
Output is correct |
4 |
Correct |
11 ms |
10608 KB |
Output is correct |
5 |
Correct |
24 ms |
14388 KB |
Output is correct |
6 |
Correct |
23 ms |
13756 KB |
Output is correct |
7 |
Correct |
27 ms |
14424 KB |
Output is correct |
8 |
Correct |
22 ms |
14416 KB |
Output is correct |
9 |
Incorrect |
22 ms |
14172 KB |
1st lines differ - on the 1st token, expected: '99999', found: '66666' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
12628 KB |
Output is correct |
2 |
Correct |
22 ms |
14456 KB |
Output is correct |
3 |
Correct |
4 ms |
8028 KB |
Output is correct |
4 |
Correct |
5 ms |
8028 KB |
Output is correct |
5 |
Correct |
63 ms |
28504 KB |
Output is correct |
6 |
Correct |
70 ms |
28888 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
Possible tampering with the output |
8 |
Halted |
0 ms |
0 KB |
- |