제출 #687637

#제출 시각아이디문제언어결과실행 시간메모리
687637Urvuk3Catfish Farm (IOI22_fish)C++17
0 / 100
51 ms10900 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<int>> we(N,vector<int>(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>(2,0))); for(int i=1;i<N;i++){ //resavam kad opada ll pref_max=0; for(int tsz=N-1;tsz>=0;tsz--){ pref_max=max(pref_max+we[i][tsz],dp[i-1][tsz][0]+we[i][tsz]); pref_max=max(pref_max+we[i][tsz],dp[i-1][tsz][1]+we[i][tsz]); dp[i][tsz][0]=pref_max; } //resavam kada raste if(i>1){ 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]; } pref_max=0; for(int tsz=1;tsz<=N;tsz++){ pref_max=max(pref_max,dp[i-2][tsz][0]); pref_max=max(pref_max,dp[i-2][tsz][1]); dp[i][tsz][1]=pref_max+pref[tsz-1]; } pref_max=0; for(int tsz=N;tsz>=1;tsz--){ pref_max=max(pref_max,dp[i-2][tsz][0]+pref[tsz-1]); pref_max=max(pref_max,dp[i-2][tsz][1]+pref[tsz-1]); dp[i][tsz][1]=max(dp[i][tsz][1],pref_max); } } pref_max=0; for(int tsz=2;tsz<=N;tsz++){ pref_max=max(pref_max+we[i-1][tsz-1],dp[i-1][tsz][1]+we[i-1][tsz-1]); dp[i][tsz][1]=max(dp[i][tsz][1],pref_max); } } ll res=0; for(int tsz=0;tsz<=N;tsz++){ res=max({res,dp[N-1][tsz][0],dp[N-1][tsz][1]}); } return res; }
#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...