Submission #1076197

#TimeUsernameProblemLanguageResultExecution timeMemory
1076197vjudge1Catfish Farm (IOI22_fish)C++17
6 / 100
104 ms16588 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using ii = pair<int, int>; using vll = vector<ll>; struct AIB { int n; bool rev; vll V; AIB(int N, bool RV) : n(N + 1), rev(RV), V(N + 1, 0) {} void update(int p, ll v) { if(rev) p = n - p - 1; ++p; while(p < n) { V[p] = max(V[p], v); p += p & -p; } } ll query(int p) { if(rev) p = n - p - 1; ++p; ll re = 0; while(p) { re = max(re, V[p]); p -= p & -p; } return re; } }; ll max_weights(int n, int m, vi X, vi Y, vi W) { vector<vector<ii> > A(n); for(int i = 0; i < m; ++i) A[X[i]].push_back({Y[i], W[i]}); for(int i = 0; i < n; ++i) { sort(A[i].begin(), A[i].end()); } vll DP_tot(n, 0), DP0(n, 0), DP1(n, 0); AIB MaPre(n, 0), MaSuf(n, 1); ll re = 0; for(int i = 0; i < n; ++i) { ll rez_min = 0; if(i > 1) rez_min = DP_tot[i - 2]; if(i + 1 < n) { for(auto [y, w] : A[i]) { /// urcam, facem 0 ll re0 = rez_min; if(MaPre.query(y - 1) > re0) re0 = MaPre.query(y - 1); re0 += w; MaPre.update(y, re0); DP0[i] = max(DP0[i], re0); } } reverse(A[i].begin(), A[i].end()); if(i) { for(auto [y, w] : A[i]) { ll re1 = rez_min; if(MaSuf.query(y + 1) > re1) re1 = MaSuf.query(y + 1); re1 += w; MaSuf.update(y, re1); MaPre.update(y, re1); DP1[i] = max(DP1[i], re1); } } DP_tot[i] = max(DP0[i], DP1[i]); re = max(re, DP_tot[i]); } return re; }
#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...