Submission #839366

#TimeUsernameProblemLanguageResultExecution timeMemory
839366TrunktyCatfish Farm (IOI22_fish)C++17
0 / 100
822 ms153104 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; //#define int ll #include "fish.h" ll arr[3005][3005],prearr[3005][3005]; ll dp[3005][3005],dp2[3005][3005]; // dp2 if adjacent AND lower ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w){ for(int i=0;i<m;i++){ arr[x[i]+1][y[i]+1] = w[i]; } for(int i=1;i<=n;i++){ for(int j=0;j<=n;j++){ prearr[i][j] = prearr[i][j-1]+arr[i][j]; } } for(int i=1;i<=n;i++){ for(int j=0;j<=n;j++){ // if first port dp[i][j] = prearr[i-1][j]+prearr[i+1][j]; if(i-1<=0){ continue; } for(int k=0;k<=n;k++){ // build port at x=i, height = j, connects to port at x=i-1, height = k if(j>k){ dp[i][j] = max(dp[i][j],dp[i-1][k]-prearr[i][k]+prearr[i+1][j]+prearr[i-1][j]-prearr[i-1][k]); } else if(j==k){ dp[i][j] = max(dp[i][j],max(dp[i-1][k],dp2[i-1][k])-prearr[i][j]+prearr[i+1][j]); } else if(j<k){ dp2[i][j] = max(dp2[i][j],max(dp[i-1][k],dp2[i-1][k])-prearr[i][j]+prearr[i+1][j]); } } if(i-2<=0){ continue; } for(int k=0;k<=n;k++){ // build port at x=i, height = j, connects to port at x=i-2, height = k dp[i][j] = max(dp[i][j],dp[i-2][k]+prearr[i-1][j]+prearr[i+1][j]-2LL*prearr[i-1][min(j,k)]); } } } ll ans=0; for(int i=0;i<=n;i++){ ans = max(ans,max(dp[n][i],dp2[n][i])); } 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...