Submission #632707

#TimeUsernameProblemLanguageResultExecution timeMemory
632707rainboyCatfish Farm (IOI22_fish)C++17
44 / 100
101 ms26168 KiB
#include "fish.h" #include <vector> using namespace std; typedef vector<int> vi; const int M = 100002; const long long INF = 0x3f3f3f3f3f3f3f3fLL; long long max(long long a, long long b) { return a > b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int ii[M], ii1[M], jj[M], jj1[M], ww[M], ww1[M]; void sort(int *hh, int l, int r) { while (l < r) { int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp; while (j < k) { int c = ii1[hh[j]] != ii1[h] ? ii1[hh[j]] - ii1[h] : jj1[hh[j]] - jj1[h]; if (c == 0) j++; else if (c < 0) { tmp = hh[i], hh[i] = hh[j], hh[j] = tmp; i++, j++; } else { k--; tmp = hh[j], hh[j] = hh[k], hh[k] = tmp; } } sort(hh, l, i); l = k; } } long long dp[M], dq[M]; long long max_weights(int n, int m, vi ii_, vi jj_, vi ww_) { static int hh[M]; for (int h = 0; h < m; h++) ii1[h] = ii_[h], jj1[h] = jj_[h], ww1[h] = ww_[h]; ii1[m] = -1, jj1[m] = -1, ww1[m] = 0, m++; ii1[m] = n, jj1[m] = -1, ww1[m] = 0, m++; for (int h = 0; h < m; h++) hh[h] = h; sort(hh, 0, m); for (int h = 0; h < m; h++) ii[h] = ii1[hh[h]], jj[h] = jj1[hh[h]], ww[h] = ww1[hh[h]]; dp[0] = -INF, dq[0] = 0; long long x = -INF, y; for (int i = 0, l = 0, h = 1, r; i <= n; i++, l = h, h = r) { r = h; while (r < m && ii[r] == i) r++; y = x; for (int f = h - 1, g = r - 1; g >= h; g--) { while (f >= l && jj[f] > jj[g]) y = max(y, dp[f--]); dp[g] = y; if (dp[g] != -INF) dp[g] += ww[g]; y = max(y, dp[g]); } for (int g = l; g < h; g++) x = max(x, dp[g]); y = x; for (int f = l, g = h; g < r; g++) { while (f < h && jj[f] < jj[g]) y = max(y, dq[f++]); dq[g] = y; if (dq[g] != -INF) dq[g] += ww[g]; y = max(y, dq[g]); } for (int g = l; g < h; g++) x = max(x, dq[g]); } return dp[m - 1]; }
#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...