# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1074239 | zsombor | Catfish Farm (IOI22_fish) | C++17 | 1053 ms | 22388 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, ans = 0;
vector<vector<pair<int, ll> > > f(2e5);
vector<vector<ll> > dp(2e5);
void get_dp(int i, int j) {
ll h0, h = f[i][j].first - 1, val = 0, nxt = 0;
for (auto p: f[i - 1]) if (p.first <= h) val += p.second;
for (auto p: f[i + 1]) if (p.first <= h) val += p.second;
dp[i][j] = val;
for (int k = 0; k < f[i - 1].size(); k++) {
h0 = f[i - 1][k].first - 1;
while (h0 >= f[i][nxt].first) val -= f[i][nxt++].second;
dp[i][j] = max(dp[i][j], dp[i - 1][k] + val);
if (f[i - 1][k].first <= h) val -= f[i - 1][k].second;
}
ans = max(ans, dp[i][j]);
}
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
n = N;
m = M;
for (int i = 0; i < m; i++) {
X[i]++;
Y[i]++;
f[X[i]].push_back({Y[i], W[i]});
}
f[0].push_back({1, 0});
for (int i = 0; i <= n + 1; i++) {
f[i].push_back({n + 1, 0});
sort(f[i].begin(), f[i].end());
}
dp[0] = {0ll, ll(-1e18)};
for (int i = 1; i <= n; i++) {
dp[i].resize(f[i].size(), 0);
for (int j = 0; j < f[i].size(); j++) get_dp(i, j);
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |