Submission #1125329

#TimeUsernameProblemLanguageResultExecution timeMemory
1125329VVUUCatfish Farm (IOI22_fish)C++20
100 / 100
162 ms44540 KiB
#include "fish.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define in array<int, 2> #define iln array<ll, 2> #define pb push_back #define pob pop_back const ll INF = 1e17; ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) { vector<in> loc[n+1];//loc[i][k] = kth from bottom in ith column. for(auto &s: x) s++; for(auto &s: y) s++; for(int i = 1; i <= n; i++) loc[i].pb({0, 0}); for(int i = 0; i < m; i++) loc[x[i]].pb({y[i], w[i]}); //pre-processing done. vector<array<ll, 4>> dp[n+1]; vector<ll> pref[n+1]; ll DP[n+1]; for(int i = 1; i <= n; i++) { sort(loc[i].begin(), loc[i].end()); loc[i].pb({n+1, 0}); pref[i].assign(loc[i].size(), 0ll); for(int j = 1; j < loc[i].size(); j++) pref[i][j] = pref[i][j-1] + loc[i][j][1]; dp[i].resize(loc[i].size()); } DP[0] = DP[1] = 0; for(int i = 2; i <= n; i++) { dp[i][0][0] = dp[i-1][0][0]; int D = loc[i-1].size()-1; ll Val = dp[i-1][D][0] + pref[i].back(); for(int j = loc[i].size()-1; j >= 0; j--) { while((D > 0) && (loc[i-1][D-1][0] > loc[i][j][0])) { D--; Val = max(Val, dp[i-1][D][0] + pref[i][j]); } if(j) dp[i][j][3] = Val - pref[i][j-1]; else dp[i][j][3] = Val; } dp[i][0][0] = max(dp[i][0][0], dp[i][0][3]); int Dd = 0; ll VAL = -INF; for(int j = 1; j < loc[i].size(); j++) { dp[i][j][1] = dp[i-1][0][0]; while(((Dd+1) < loc[i-1].size()) && (loc[i-1][Dd+1][0] < loc[i][j][0])) { Dd++; VAL = max(VAL, dp[i-1][Dd][2] - pref[i-1][Dd-1]); } dp[i][j][2] = max(DP[i-2], VAL) + pref[i-1][Dd]; } DP[i] = dp[i][0][0]; for(int j = 1; j < loc[i].size(); j++) { dp[i][j][0] = max(max(dp[i][j][1], dp[i][j][2]), dp[i][j][3]); DP[i] = max(DP[i], dp[i][j][0]); } } return DP[n]; }
#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...