Submission #1074077

#TimeUsernameProblemLanguageResultExecution timeMemory
1074077Gromp15Catfish Farm (IOI22_fish)C++17
40 / 100
1020 ms2097152 KiB
#include <bits/stdc++.h> #include "fish.h" #define ll long long #define ar array #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() using namespace std; const ll INF = 1e18; template<typename T> bool ckmin(T &a, const T &b ) { return a > b ? a = b, 1 : 0; } template<typename T> bool ckmax(T &a, const T &b ) { return a < b ? a = b, 1 : 0; } long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y, std::vector<int> w) { vector<vector<ar<ll, 2>>> each(n); for (int i = 0; i < m; i++) { each[x[i]].push_back({y[i], w[i]}); each[x[i]].push_back({y[i]-1, 0}); } for (int i = 0; i < n; i++) each[i].push_back({n-1, 0}), each[i].push_back({-1, 0}); for (int i = 0; i < n; i++) { sort(all(each[i])); vector<ar<ll, 2>> nw; ll s = 0; for (int j = 0; j < sz(each[i]); j++) { int r = j; while (r+1 < sz(each[i]) && each[i][r+1][0] == each[i][r][0]) r++; for (int k = j; k <= r; k++) s += each[i][k][1]; nw.push_back({each[i][j][0], s}); j = r; } swap(each[i], nw); } vector<vector<ll>> dp; auto query = [&](int pos, int x) { return (*prev(upper_bound(all(each[pos]), ar<ll, 2>{x, LLONG_MAX})))[1]; }; for (int i = 0; i < n; i++) { vector<vector<ll>> dp2; const int N = sz(each[i]); dp2.resize(i ? sz(each[i-1]) : 1, vector<ll>(N, -INF)); if (!i) { for (int j = 0; j < N; j++) { dp2[0][j] = 0; } swap(dp, dp2); } else { for (int j = 0; j < sz(dp); j++) { for (int k = 0; k < sz(dp[j]); k++) { for (int l = 0; l < N; l++) { int L = each[i-1][k][0], R = max(i-2 >= 0 ? each[i-2][j][0] : -1, each[i][l][0]); ckmax(dp2[k][l], dp[j][k] + (L <= R ? query(i-1, R) - query(i-1, L) : 0)); } } } swap(dp, dp2); } } ll ans = -INF; for (int i = 0; i < sz(dp); i++) { for (int j = 0; j < sz(dp[i]); j++) { int L = each[n-1][j][0], R = each[n-2][i][0]; ckmax(ans, dp[i][j] + (L <= R ? query(n-1, R) - query(n-1, L) : 0)); } } 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...