Submission #644036

#TimeUsernameProblemLanguageResultExecution timeMemory
644036NintsiChkhaidzeCatfish Farm (IOI22_fish)C++17
52 / 100
753 ms718496 KiB
#include "fish.h" #include <bits/stdc++.h> #define ll long long using namespace std; const int N = 3005; ll p[N][N],dp[N][N][5],suff[N][N],pref[N][N],sfc[N][N],prc[N][N]; ll max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W) { for (int i = 0;i < m; i++){ X[i]++,Y[i]++; p[X[i]][Y[i]] += W[i]; } for (int j = 1; j <= n; j++) for (int i = 1; i <= n; i++) p[j][i] += p[j][i - 1]; for (int j = 1; j <= n; j++){ for (int a = 0; a <= n; a++){ //update dp[j][a][0] dp[j][a][0] = max(dp[j][a][0], suff[j - 1][a] - p[j][a]); //update dp[j][a][1] dp[j][a][1] = max(dp[j][a][1], pref[j - 1][a] + p[j - 1][a]); //c 0 a if (j >= 3){ dp[j][a][1] = max(dp[j][a][1], prc[j - 2][a] + p[j - 1][a]); dp[j][a][1] = max(dp[j][a][1], sfc[j - 2][a]); } } for (int a = n; a >= 0; a--) suff[j][a] = max(suff[j][a+1],max(dp[j][a][0],dp[j][a][1]) + p[j + 1][a]); pref[j][0] = dp[j][0][1] - p[j][0]; for (int a =1; a <= n; a++) pref[j][a] = max(pref[j][a - 1],dp[j][a][1] - p[j][a]); prc[j][0] = max(dp[j][0][0],dp[j][0][1]); for (int a = 1; a <= n; a++) prc[j][a] = max(prc[j][a - 1], max(dp[j][a][0],dp[j][a][1])); for (int a = n; a >= 0; a--) sfc[j][a] = max(sfc[j][a + 1],max(dp[j][a][0],dp[j][a][1]) + p[j + 1][a]); } ll ans = 0; for (int a = 0; a <= n; a++) ans=max(ans,max(dp[n][a][0],dp[n][a][1])); 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...