Submission #731277

#TimeUsernameProblemLanguageResultExecution timeMemory
731277alextodoran메기 농장 (IOI22_fish)C++17
0 / 100
113 ms12040 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; const ll INF = LLONG_MAX / 3; 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()] = -INF; 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 = -INF; for (int i = pos; i >= 1; i -= i & -i) { val = max(val, Fen[i]); } return val; } ll dpUp[M_MAX + 2]; ll dpDown[M_MAX + 2]; ll fullUp[M_MAX + 2]; ll fullDown[M_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); } fill(Fen + 1, Fen + N + 1, -INF); fullUp[0] = -INF; for (int x = 1; x <= N; x++) { sort(onX[x].begin(), onX[x].end(), [&] (const int &i, const int &j) { return Y[i] < Y[j]; }); init(); update(1, fullDown[x]); for (int i : onX[x - 1]) { update(Y[i], dpUp[i]); } for (int i : onX[x]) { dpUp[i] = query(Y[i] - 1) + W[i]; update(Y[i], dpUp[i]); } fullUp[x + 1] = max({fullUp[x], fullDown[x], query(N)}); reverse(onX[x].begin(), onX[x].end()); init(); update(1, fullUp[x - 1]); for (int i : onX[x - 1]) { update((N - Y[i] + 1), dpDown[i]); } for (int i : onX[x]) { dpDown[i] = query((N - Y[i] + 1) - 1) + W[i]; update((N - Y[i] + 1), dpDown[i]); } fullDown[x + 1] = max({fullUp[x], fullDown[x], query(N)}); reverse(onX[x].begin(), onX[x].end()); } return max(fullDown[N + 1], fullUp[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...