Submission #1072316

#TimeUsernameProblemLanguageResultExecution timeMemory
1072316vjudge1Catfish Farm (IOI22_fish)C++17
0 / 100
1040 ms8384 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 last pier in column <= i-1 and also\ caught the first j catfish from column i // pier worth extending up to every catfish or until the end (O(n+m) optimal maximal piers) const ll MAXN = 3E3+16, INF = ll(1E18)+16; ll dp[MAXN][MAXN]; vii ccs[MAXN]; // vll ps[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], 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; return (upper_bound(ccs[x].begin(), ccs[x].end(), ii{ y-1, 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, y2) + fget(x2, y1); } assert(false); }; ll ans = 0; for (ll x = 0; x < n; x++) { for (ll y = 0; y <= n; y++) { ll ra = fget(x-1, y) + fget(x+1, y); dp[x][y] = ra; for (ll x2 = max(0LL, x-3); 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 << dp[x][y] << ' '; ans = max(ans, dp[x][y]); } // cerr << '\n'; } return ans; }

Compilation message (stderr)

fish.cpp:10:1: warning: multi-line comment [-Wcomment]
   10 | // dp[i][j] = max grams caught if last pier in column <= i-1 and also\
      | ^
#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...