Submission #797781

#TimeUsernameProblemLanguageResultExecution timeMemory
797781hugo_pmCatfish Farm (IOI22_fish)C++17
0 / 100
876 ms2097152 KiB
#include <bits/stdc++.h> #include "fish.h" using namespace std; #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define rep(i, a, b) for(int i = (a); i < (b); i++) #define sz(v) ((int)((v).size())) template<typename T> void chmax(T &x, const T &v) { if (x < v) x = v; } template<typename T> void chmin(T &x, const T &v) { if (x > v) x = v; } using ll = long long; using v64 = vector<ll>; using a2v64 = array<v64, 2>; using p64 = pair<ll, ll>; string to_string(string s) { return s; } template <typename T> string to_string(T v) { bool first = true; string res = "["; for (const auto &x : v) { if (!first) res += ", "; first = false; res += to_string(x); } res += "]"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } void dbg_out() { cout << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << to_string(H); dbg_out(T...); } #ifdef DEBUG #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif const ll INF = 3e18; const int INCR = 0, DECR = 1; ll max_weights(int szCarre, int nbFish, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { ++szCarre; vector<v64> carre(szCarre, v64(szCarre)); vector<vector<bool>> nice(szCarre, vector<bool>(szCarre+1, false)); rep(i, 0, nbFish) { ++X[i]; carre[X[i]][Y[i]] = W[i]; nice[X[i]-1][Y[i]] = true; if (X[i]+1 < szCarre) { nice[X[i]+1][Y[i]] = true; } } vector<v64> prefSum(szCarre, v64(szCarre+1, 0)); rep(col, 0, szCarre) { nice[col][0] = nice[col][szCarre] = true; auto &ss = prefSum[col]; rep(lig, 0, szCarre) { ss[lig+1] = ss[lig] + carre[col][lig]; } } a2v64 minInf; minInf[0] = minInf[1] = v64(szCarre+1, -INF); a2v64 dpOld = minInf; dpOld[INCR][0] = dpOld[DECR][0] = 0; rep(col, 1, szCarre) { a2v64 dpNew = minInf; dpNew[INCR][0] = *max_element(all(dpOld[DECR])); if (true) { auto &sumPrev = prefSum[col-1]; ll maxTr = -INF; rep(take, 0, szCarre+1) { int ptrNice = take; while (!nice[col-1][ptrNice]) --ptrNice; chmax(maxTr, dpOld[INCR][ptrNice] - sumPrev[take]); chmax(dpNew[INCR][take], maxTr + sumPrev[take]); } } if (true) { auto &sumCur = prefSum[col]; ll maxTr = -INF; for (int take = szCarre; take >= 0; --take) { int ptrNice = take; while (!nice[col-1][ptrNice]) ++ptrNice; chmax(maxTr, dpOld[DECR][ptrNice] + sumCur[take]); chmax(dpNew[DECR][take], maxTr - sumCur[take]); } } rep(take, 0, szCarre+1) { if (nice[col][take]) chmax(dpNew[DECR][take], dpNew[INCR][take]); else dpNew[INCR][take] = dpNew[DECR][take] = -INF; } dpOld = dpNew; } return *max_element(all(dpOld[DECR])); }
#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...