Submission #680378

#TimeUsernameProblemLanguageResultExecution timeMemory
680378whqkrtk04Catfish Farm (IOI22_fish)C++17
35 / 100
1066 ms2097152 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef pair<ll, ll> pll; typedef pair<ll, pll> plll; #define fi first #define se second const int INF = 1e9+1; const int P = 1000000007; const ll LLINF = (ll)1e18+1; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for(auto i : v) os << i << " "; os << "\n"; return os; } template <typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { os << p.fi << " " << p.se; return os; } typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vvll> vvvll; typedef struct prefix_sum { vector<vector<pll>> B; ll operator()(int x, int s, int e) { assert(s <= e); return this->operator()(x, e)-this->operator()(x, s); } ll operator()(int x, int y) { if(x < 0 || x >= B.size()) return 0LL; auto iter = lower_bound(B[x].begin(), B[x].end(), pll(y, 0LL)); return (iter == B[x].begin() ? 0LL : (--iter)->se); } prefix_sum(vector<vector<pii>> &A) { for(auto &i : A) { ll su = 0LL; B.push_back(vector<pll>()); for(auto &j : i) { su += j.se; B.back().push_back({j.fi, su}); } } } } prefix_sum; ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) { vector<vector<pii>> brd(N); for(int i = 0; i < M; i++) brd[X[i]].push_back({Y[i], W[i]}); for(int i = 0; i < N; i++) sort(brd[i].begin(), brd[i].end()); prefix_sum pre(brd); int MX = N, MY = N+1; vvll down(MX, vll(MY, 0LL)), dp(MX, vll(MY, 0LL)); for(int j = 0; j < MY; j++) { down[0][j] = dp[0][j] = pre(1, j); down[1][j] = pre(0, j)+pre(2, j); dp[1][j] = max(down[1][j], pre(1, j, N)+pre(2, j)); } for(int i = 2; i < MX; i++) { vll A, B, C, D; for(int j = 0; j < MY; j++) { A.push_back(down[i-1][j]-pre(i, j)-pre(i-1, j)); // bug22? B.push_back(dp[i-2][j]-pre(i-1, j)); // bug? C.push_back(dp[i-2][j]); D.push_back(dp[i-1][j]); } for(int j = 1; j < MY; j++) { A[j] = max(A[j], A[j-1]); B[j] = max(B[j], B[j-1]); } for(int j = MY-2; j >= 0; j--) { C[j] = max(C[j], C[j+1]); D[j] = max(D[j], D[j+1]); } for(int j = 0; j < MY; j++) { down[i][j] = max(A[j], B[j])+pre(i-1, j)+pre(i+1, j); if(j+1 < MY) { down[i][j] = max(down[i][j], C[j+1]+pre(i+1, j)); dp[i][j] = D[j+1]-pre(i, j)+pre(i+1, j); } dp[i][j] = max(dp[i][j], down[i][j]); } } //cout << " " << down << " " << dp << "\n"; return *max_element(dp.back().begin(), dp.back().end()); }

Compilation message (stderr)

fish.cpp: In member function 'll prefix_sum::operator()(int, int)':
fish.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         if(x < 0 || x >= B.size()) return 0LL;
      |                     ~~^~~~~~~~~~~
#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...