Submission #688510

#TimeUsernameProblemLanguageResultExecution timeMemory
688510Urvuk3Catfish Farm (IOI22_fish)C++17
0 / 100
49 ms8328 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; #define ll long long const int INF=1e9; const ll LINF=1e18; #define fi first #define se second #define pii pair<int,int> #define mid ((l+r)/2) #define sz(a) (int((a).size())) #define all(a) a.begin(),a.end() #define endl "\n" #define PRINT(x) cerr<<#x<<'='<<x<<endl; #define pb push_back #define PRINTvec(niz) { cerr<<#niz<<"="; for(auto _i:niz) cerr<<_i<<" "; cerr<<endl; } long long max_weights(int N,int M,vector<int> X,vector<int> Y,vector<int> W){ assert(N<=3000); vector<vector<ll>> we(N,vector<ll>(N,0)); for(int i=0;i<M;i++){ we[X[i]][Y[i]]=W[i]; } vector<vector<vector<ll>>> dp(N,vector<vector<ll>>(N+1,vector<ll>(3,0))); for(int i=1;i<N;i++){ ll pref_max=0; for(int tsz=N-1;tsz>=0;tsz--){ pref_max=max(pref_max+we[i][tsz],max({dp[i-1][tsz+1][0],dp[i-1][tsz+1][1],dp[i-1][tsz+1][2]})+we[i][tsz]); dp[i][tsz][0]=pref_max; } for(int tsz=N;tsz>=0;tsz--){ dp[i][tsz][2]=dp[i-1][tsz][0]; } vector<ll> pref(N,0); pref[0]=we[i-1][0]; for(int j=1;j<N;j++){ pref[j]=pref[j-1]+we[i-1][j]; } if(i>1){ pref_max=0; for(int tsz=1;tsz<=N;tsz++){ pref_max=max(pref_max,max({dp[i-2][tsz][0],dp[i-2][tsz][1],dp[i-2][tsz][2]})); dp[i][tsz][1]=pref_max+pref[tsz-1]; } pref_max=0; for(int tsz=N;tsz>=1;tsz--){ pref_max=max(pref_max,max({dp[i-2][tsz][0],dp[i-2][tsz][1],dp[i-2][tsz][2]})+pref[tsz-1]); dp[i][tsz][1]=max(dp[i][tsz][1],pref_max); } } else{ for(int tsz=1;tsz<=N;tsz++){ dp[i][tsz][1]=pref[tsz-1]; } } pref_max=0; for(int tsz=2;tsz<=N;tsz++){ pref_max=max(pref_max+we[i-1][tsz-1],max(dp[i-1][tsz-1][1],dp[i-1][tsz-1][2])+we[i-1][tsz-1]); dp[i][tsz][1]=max(dp[i][tsz][1],pref_max); } } /* for(int i=0;i<N;i++){ PRINT(i); for(int p=0;p<3;p++){ for(int tsz=0;tsz<=N;tsz++){ cerr<<"dp["<<i<<"]["<<tsz<<"]["<<p<<"]="<<dp[i][tsz][p]<<endl; } cerr<<endl; } cerr<<"XXXXXXXXXXXXXXXXXXXXX"<<endl<<endl; } */ ll res=0; for(int tsz=0;tsz<=N;tsz++){ res=max({res,dp[N-1][tsz][0],dp[N-1][tsz][1],dp[N-1][tsz][2]}); } return res; } /* 7 8 1 3 10 2 2 1 3 0 1 3 1 10 4 2 10 5 3 10 5 4 10 6 6 1000 */
#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...