Submission #1072425

#TimeUsernameProblemLanguageResultExecution timeMemory
1072425vjudge1Catfish Farm (IOI22_fish)C++17
14 / 100
46 ms17388 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector <ll>; using ii = pair <ll, ll>; using vii = vector <ii>; using vi = vector <int>; // dp[i][j] = max grams caught if caught catfish until j from column i-1 // pier worth extending up to every catfish or until the end (O(n+m) optimal maximal piers) const ll MAXN = 3E2+16, INF = ll(1E18)+16; ll dp[MAXN][10][10]; vii ccs[MAXN]; ll max_weights (int n, int m, vi vx, vi vy, vi vw) { for (ll i = 0; i < m; i++) ccs[vx[i]].push_back({ vy[i]+1, vw[i] }); for (ll x = 0; x < n; x++) { sort(ccs[x].begin(), ccs[x].end()); ccs[x].insert(ccs[x].begin(), ii{ -1, 0 }); // ps[x].push_back(0); ll acc = 0; for (auto &[y, w] : ccs[x]) { acc += w; w = acc; } } auto fget = [&](ll x, ll y) -> ll { // pier at column x up until y // ll ans = 0; if (x < 0 || n <= x) return 0; // assert(upper_bound(ccs[x].begin(), ccs[x].end(), ii{ y, INF })-1 != ccs[x].end()); return (upper_bound(ccs[x].begin(), ccs[x].end(), ii{ y, INF })-1)->second; // if () }; // auto ffix = [&](ll x1, ll y1, ll x2, ll y2) -> ll { // fix the combination of those dps // assert(x1 < x2); // if (x1+2 < x2) return 0; // if (x1+2 == x2) { // return fget(x1+1, min(y1, y2)); // } // if (x1+1 == x2) { // return fget(x1, min(y1, y2)) + fget(x2, min(y1, y2)); // } // assert(false); // }; auto finc = [&](ll x, ll y1, ll y2, ll y3) -> ll { // fix the combination of those dps ll unav = max(y1, y2); // fget(x-2, y1) // fget(x-1, y2) if (y3 > unav) return fget(x-1, y3) - fget(x-1, unav) + fget(x+1, y3) - fget(x, min(y2, y3)); return fget(x+1, y3) - fget(x, min(y2, y3)); }; ll ans = 0; for (ll x = 0; x < n; x++) { for (ll y1 = 0; y1 <= 9; y1++) { for (ll y2 = 0; y2 <= 9; y2++) { for (ll y3 = 0; y3 <= 9; y3++) { dp[x][y2][y3] = max(dp[x][y2][y3], (x?dp[x-1][y1][y2]:0) + finc(x, y1, y2, y3)); ans = max(ans, dp[x][y2][y3]); } } // ll ra = /* fget(x-1, y) + */fget(x+1, y); // dp[x][y][0] = ra; // dp[x][y][0] = ra; // if (x == 0) { dp[x][0][y] = ra; continue; } // for (ll y2 = 0; y2 <= 9; y2++) { // ll &ans = dp[x][y2][y]; // for (ll y3 = 0; y3 <= 9; y3++) { // ; // } // // if (dp[x2][y2]+ra-ffix(x2, y2, x, y) == 11) cerr << " " << x2 << ' ' << y2 << '\n'; // dp[x][y] = max(dp[x][y], dp[x2][y2] + ra - ffix(x2, y2, x, y)); // } // for (ll x2 = x-1; x2 < x; x2++) { // for (ll y2 = 0; y2 <= n; y2++) { // dp[x][y] = max(dp[x][y], dp[x2][y2] + ra - ffix(x2, y2, x, y)); // } // } // cerr << x << ' ' << y << ": "; // for (ll x2 = max(0LL, x-3); x2 < x; x2++) { // } // cerr << dp[x][y] << '\n'; } // cerr << '\n'; } 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...