Submission #938545

#TimeUsernameProblemLanguageResultExecution timeMemory
938545irmuunCatfish Farm (IOI22_fish)C++17
32 / 100
75 ms14032 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() ll max_weights(int n,int m,vector<int>x,vector<int>y,vector<int>w){ int even=0,X=0,Y=0; for(int i=0;i<m;i++){ X=max(X,x[i]); Y=max(Y,y[i]); if(x[i]%2==0) even++; } if(even==m){ ll ans=0; for(int i=0;i<m;i++){ ans+=w[i]; } return ans; } if(X<=1){ ll ans=0,cur=0; for(int i=0;i<m;i++){ if(x[i]==0){ ans+=w[i]; } else{ cur+=w[i]; } } if(n==2) return max(ans,cur); ll sum[n][2]; memset(sum,0,sizeof sum); for(int i=0;i<m;i++){ sum[y[i]][x[i]]+=w[i]; } for(int i=1;i<n;i++){ sum[i][0]+=sum[i-1][0]; sum[i][1]+=sum[i-1][1]; } ans=max(ans,cur); for(int i=0;i<n;i++){ ans=max(ans,sum[i][0]+sum[n-1][1]-sum[i][1]); } return ans; } if(Y==0){ ll sum[n]; fill(sum,sum+n,0); for(int i=0;i<m;i++){ sum[x[i]]=w[i]; } ll dp[n][2][2]; dp[1][0][0]=0; dp[1][1][0]=sum[0]; dp[1][0][1]=sum[1]; dp[1][1][1]=0; for(ll i=2;i<n;i++){ dp[i][1][1]=max(dp[i-1][1][0],dp[i-1][1][1]); dp[i][1][0]=max(dp[i-1][0][1],dp[i-1][0][0]+sum[i-1]); dp[i][0][1]=max(dp[i-1][1][0],dp[i-1][1][1])+sum[i]; dp[i][0][0]=max(dp[i-1][0][1],dp[i-1][0][0]); } return max({dp[n-1][0][0],dp[n-1][0][1],dp[n-1][1][0],dp[n-1][1][1]}); } if(n<=300&&Y<=8){ ll dp[n][9][9]; memset(dp,0,sizeof dp); ll sum[n][9]; memset(sum,0,sizeof sum); for(ll i=0;i<m;i++){ sum[x[i]][y[i]]=w[i]; } for(int i=0;i<9;i++){ for(int j=0;j<9;j++){ if(i<=j){ for(int k=i;k<j;k++){ dp[1][i][j]+=sum[0][k]; } } else{ for(int k=j;k<i;k++){ dp[1][i][j]+=sum[1][k]; } } } } for(int col=2;col<n;col++){ for(int i=0;i<9;i++){ for(int j=0;j<9;j++){ for(int k=0;k<9;k++){ ll tot=0; if(j<k){ if(i<k){ for(int r=max(i,j);r<k;r++){ tot+=sum[col-1][r]; } } } else{ for(int r=k;r<j;r++){ tot+=sum[col][r]; } } dp[col][j][k]=max(dp[col][j][k],dp[col-1][i][j]+tot); } } } } ll ans=0; for(int i=0;i<9;i++){ for(int j=0;j<9;j++){ ans=max(ans,dp[n-1][i][j]); } } return ans; } return 0ll; }
#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...