Submission #731243

#TimeUsernameProblemLanguageResultExecution timeMemory
731243alextodoranCatfish Farm (IOI22_fish)C++17
0 / 100
89 ms19256 KiB
/** _ _ __ _ _ _ _ _ _ |a ||t ||o d | |o | | __ _| | _ | __| _ | | __ |/_ | __ /__\ / _\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N_MAX = 100000; const int M_MAX = 300000; int N, M; int X[M_MAX + 2], Y[M_MAX + 2], W[M_MAX + 2]; vector <int> onX[N_MAX + 2]; ll Fen[N_MAX + 2]; vector <int> updi; void init () { while (updi.empty() == false) { Fen[updi.back()] = 0; updi.pop_back(); } } void update (int pos, ll val) { for (int i = pos; i <= N; i += i & -i) { updi.push_back(i); Fen[i] = max(Fen[i], val); } } ll query (int pos) { ll val = 0; for (int i = pos; i >= 1; i -= i & -i) { val = max(val, Fen[i]); } return val; } ll dp[M_MAX + 2][2]; ll mxdp[N_MAX + 2]; ll max_weights (int _N, int _M, vector <int> _X, vector <int> _Y, vector <int> _W) { N = _N; M = _M; for (int i = 1; i <= M; i++) { X[i] = _X[i - 1] + 1; Y[i] = _Y[i - 1] + 1; W[i] = _W[i - 1]; onX[X[i]].push_back(i); } for (int x = 1; x <= N; x++) { if (x < N) { init(); for (int i : onX[x - 1]) { update(Y[i], dp[i][0]); } for (int i : onX[x]) { dp[i][0] = query(Y[i] - 1) + W[i]; } } if (x > 1){ init(); for (int i : onX[x - 1]) { update((N - Y[i] + 1), dp[i][1]); } for (int i : onX[x]) { dp[i][1] = query((N - Y[i] + 1) - 1) + W[i]; } } if (x >= 2) { for (int i : onX[x]) { dp[i][0] = max(dp[i][0], mxdp[x - 2] + W[i]); dp[i][1] = max(dp[i][1], mxdp[x - 2] + W[i]); } } mxdp[x] = mxdp[x - 1]; for (int i : onX[x]) { mxdp[x] = max({mxdp[x], dp[i][0], dp[i][1]}); } } return mxdp[N]; }
#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...