Submission #797769

#TimeUsernameProblemLanguageResultExecution timeMemory
797769hugo_pmCatfish Farm (IOI22_fish)C++17
52 / 100
790 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 pii = pair<int, int>; 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 using ll = long long; using v64 = vector<ll>; using a2v64 = array<v64, 2>; 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) { vector<v64> carre(szCarre, v64(szCarre)); rep(i, 0, nbFish) { carre[X[i]][Y[i]] = W[i]; } vector<v64> prefDecale(szCarre+1, v64(szCarre+1, 0)); rep(col, 0, szCarre) { auto &ss = prefDecale[col+1]; 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, 0, szCarre) { a2v64 dpNew = minInf; dpNew[INCR][0] = *max_element(all(dpOld[DECR])); if (true) { auto &sumPrev = prefDecale[col]; ll maxTr = -INF; rep(take, 0, szCarre+1) { chmax(maxTr, dpOld[INCR][take] - sumPrev[take]); chmax(dpNew[INCR][take], maxTr + sumPrev[take]); } } if (true) { auto &sumCur = prefDecale[col+1]; ll maxTr = -INF; for (int take = szCarre; take >= 0; --take) { chmax(maxTr, dpOld[DECR][take] + sumCur[take]); chmax(dpNew[DECR][take], maxTr - sumCur[take]); } } rep(take, 0, szCarre+1) { chmax(dpNew[DECR][take], dpNew[INCR][take]); } 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...