Submission #724350

#TimeUsernameProblemLanguageResultExecution timeMemory
724350nihaddhuseynliCatfish Farm (IOI22_fish)C++17
18 / 100
94 ms14304 KiB
#include "fish.h" #include <bits/stdc++.h> #include <vector> using namespace std; typedef long long int ll; long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W) { ll ans =0; ll a[300005]; ll flag=0,flag1=0; for(int i =0;i<M;i++) { if(X[i]%2==1) { flag=1; } if(Y[i]!=0) { flag1=1; } a[X[i]]+=W[i]; } if(flag==0) { ans=0; for(int i =0;i<M;i++) { ans+=W[i]; } } else if(flag1==0) { ans=0; ll dp[300005][2]; memset(dp,0,sizeof(dp)); dp[1][0]=a[1]; dp[1][1]=a[0]; for(int i =2;i<N;i++) { dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][0]); dp[i][1]=max({dp[i-2][0]+a[i-1],dp[i-1][1],dp[i-2][1]+a[i-1]}); } ans=max(dp[N-1][0],dp[N-1][1]); } else { ll b[300005][2]; memset(b,0,sizeof(b)); for(int i =0;i<M;i++) { b[Y[i]][X[i]]+=W[i]; } for(int i =1;i<N;i++) { b[i][0]+=b[i-1][0]; b[i][1]+=b[i-1][1]; } ans=max(b[N-1][0],b[N-1][1]); if(N>2) { for(int i =0;i<N;i++) { ll cnt=b[N-1][1]-b[i][1]; ans=max(ans,cnt+b[i][0]); } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...