Submission #796667

#TimeUsernameProblemLanguageResultExecution timeMemory
796667adrilen메기 농장 (IOI22_fish)C++17
14 / 100
1062 ms13724 KiB
#include "fish.h" #include<bits/stdc++.h> using namespace std; using ll = long long; typedef pair<int, int> pii; using arr = array<ll, 2>; constexpr int maxn = 305, maxm = 3e5; int n, m; vector <arr> fish[maxn]; ll dp[maxn][3][maxn] = { 0 }; long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { n = N, m = M; for (int &i: X) i++; for (int &i : Y) i++; for (int i = 0; i < maxn; i++) fish[i].push_back({0, 0}); for (int i = 0; i < m; i++) { fish[X[i]].push_back(arr{Y[i], W[i]}); } for (int i = 0; i <= n; i++) sort(fish[i].begin(), fish[i].end()); for (int i = 1; i <= n; i++) { for (int y = 1; y < (int)fish[i].size(); y++) { fish[i][y][1] += fish[i][y - 1][1]; } } // Case 0: du er på bunnen // Case 1: stigende ll output = 0; for (int x = 2; x <= n + 1; x++) { for (int y = 0; y <= n; y++) { /* Case 0 */ // Case 0, 0 (y er her forrige i stedet for kommende) for (int y = 0; y <= n; y++) { dp[x][0][0] = max(dp[x][0][0], dp[x - 1][0][y]); } dp[x][0][y] = max( dp[x - 1][1][y], dp[x - 1][2][y] ) + (*(upper_bound(fish[x].begin(), fish[x].end(), arr{y + 1, -1}) - 1))[1]; // Mengden fisk /* Case 1 Stigende */ for (int a = 1; a <= y; a++) { dp[x][1][y] = max( dp[x][1][y], dp[x - 1][1][a] + (*(upper_bound(fish[x - 1].begin(), fish[x - 1].end(), arr{y + 1, -1}) - 1))[1] - (*(upper_bound(fish[x - 1].begin(), fish[x - 1].end(), arr{a + 1, -1}) - 1))[1] ); } for (int a = 0; a <= n; a++) { dp[x][1][y] = max( dp[x][1][y], dp[x - 1][0][a] + max((*(upper_bound(fish[x - 1].begin(), fish[x - 1].end(), arr{y + 1, -1}) - 1))[1] - (*(upper_bound(fish[x - 1].begin(), fish[x - 1].end(), arr{a + 1, -1}) - 1))[1], 0ll) ); } /* Case 2 Fallende */ for (int a = y + 1; a <= n; a++) { dp[x][2][y] = max( dp[x][2][y], max(dp[x - 1][1][a], dp[x - 1][2][a]) + (*(upper_bound(fish[x].begin(), fish[x].end(), arr{a + 1, -1}) - 1))[1] - (*(upper_bound(fish[x].begin(), fish[x].end(), arr{y + 1, -1}) - 1))[1] ); } } } // for (int x = 0; x <= n + 1; x++) // { // cout << "x: " << x << "\n"; // for (int y = 0; y < 3; y++) // { // for (int c = 0; c <= n; c++) cout << dp[x][y][c] << " "; // cout << "\n"; // } // cout << "\n"; // } for (int i = 0; i <= n; i++) output = max(output, dp[n + 1][0][i]); return output; } /* for (int a = 0; a <= n; a++) // Gammel { // Case 1: stigende // Forrige må være case 0, eller også stigende for (int y = 0; y <=n; y++) { dp[x][1][y] = max(dp[x][1][y], dp[x - 1][0][a] + (*(upper_bound(fish[x - 1].begin(), fish[x - 1].end(), arr{y + 1, -1})))[1] - (*(upper_bound(fish[x - 1].begin(), fish[x - 1].end(), arr{a + 1, -1})))[1] ); } for (int y = a; y <= n; y++) { dp[x][1][y] = max(dp[x][1][y], dp[x - 1][1][a] + (*(upper_bound(fish[x - 1].begin(), fish[x - 1].end(), arr{y + 1, -1})))[1] - (*(upper_bound(fish[x - 1].begin(), fish[x - 1].end(), arr{a + 1, -1})))[1] ); } // Case 2: fallende // Forrige må ha vært stigende eller fallende // Fallende for (int y = 1; y < a; y++) { dp[x][2][y] = max(dp[x][2][y], dp[x - 1][2][a] - (*(upper_bound(fish[x].begin(), fish[x].end(), arr{y + 1, -1})))[1] + (*(upper_bound(fish[x].begin(), fish[x].end(), arr{a + 1, -1})))[1] ); } // stigende for (int y = a; y <= n; y++) { dp[x][2][y] = max(dp[x][2][y], dp[x - 1][1][a] + (*(upper_bound(fish[x].begin(), fish[x].end(), arr{y + 1, -1})))[1] + (*(upper_bound(fish[x].begin(), fish[x].end(), arr{a + 1, -1})))[1] ); } if (x == 1) break; } */
#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...