Submission #828330

#TimeUsernameProblemLanguageResultExecution timeMemory
828330petezaCatfish Farm (IOI22_fish)C++17
12 / 100
714 ms71208 KiB
#include "fish.h" #include <vector> #include <algorithm> #include <iostream> #include <climits> #include <map> using namespace std; using ll = long long; using pll = pair<ll, ll>; int n, m; vector<pll> pts[100005]; vector<int> dppoints[100005]; long long getsum(int col, int row) { if(col == -1 || col == n) return 0; auto it = upper_bound(pts[col].begin(), pts[col].end(), pll(row, LLONG_MAX)); if(it == pts[col].begin()) return 0; return (--it)->second; } ll f1[100005], f2[100005], f3[100005], f4[100005]; map<int, ll> DP[100005]; vector<int> used; void upd(ll*fwk, int idx, ll val) { for(;idx<=100000;idx+=idx&-idx) { fwk[idx] = max(fwk[idx], val); used.push_back(idx); } } ll qr(ll* fwk, int idx) { ll cmax = 0; for(;idx;idx-=idx&-idx) cmax = max(cmax, fwk[idx]); return cmax; } long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { n = N; m = M; for(int i=0;i<X.size();i++) { pts[X[i]].emplace_back(Y[i], i); if(X[i] != 0) dppoints[X[i]-1].push_back(Y[i]); if(X[i] != N-1)dppoints[X[i]+1].push_back(Y[i]); } for(int i=0;i<N;i++) { if(pts[i].empty()) continue; sort(pts[i].begin(), pts[i].end()); pts[i][0].second = W[pts[i][0].second]; for(int j=1;j<pts[i].size();j++) { pts[i][j].second = pts[i][j-1].second + W[pts[i][j].second]; } } long long best = 0, cur_im1y = 0; for(int col=0;col<N;col++) { sort(dppoints[col].begin(), dppoints[col].end()); dppoints[col].resize(unique(dppoints[col].begin(), dppoints[col].end())-dppoints[col].begin()); for(int row:dppoints[col]) { ll Wij = getsum(col, row), Wipj=getsum(col+1,row), Wimj=getsum(col-1,row); ll &cdp = DP[col][row]; cdp = cur_im1y + Wipj + Wimj; if(col != 0) { //max{k <= j}(DP[i-1][k]) - sum{m<=k}(w[i][m]) //max{k > j}(DP[i-1][k]) - sum{m<=j}(w[i][m]) long long cbest = max(qr(f1, row+1), qr(f2, n-row) - Wij); //cout << qr(f1, row+1) << ' ' << qr(f2, n-row) << '\n'; cdp = max(cbest+Wipj, cdp); } if(col>1) { //max{k <= j}(DP[i-2][k]) - sum{m<=k}(w[i-1][m]) //max{k > j}(DP[i-2][k]) - sum{m<=j}(w[i-1][m]) long long cbest = max(qr(f3, row+1) + Wimj, qr(f4, n-row)-Wimj); cdp = max(cbest + Wipj, cdp); } best = max(best, cdp); } if(col!=0) { for(int e:used) f1[e] = f2[e] = f3[e] = f4[e] = 0; used.clear(); for(int row:dppoints[col-1]) { upd(f3, row+1, DP[col-1][row] - getsum(col, row)); upd(f4, n-row, DP[col-1][row]); } } if(col >= 2) for(int row:dppoints[col-2]) cur_im1y = max(cur_im1y, DP[col-2][row]); //cout << "-----\n" << col << '\n'; for(int row:dppoints[col]) { //cout << row << ": " << DP[col][row] << ' '; //cout << '\n'; upd(f1, row+1, DP[col][row] - getsum(col+1, row)); upd(f2, n-row, DP[col][row]); } //buildfwk } return best; }

Compilation message (stderr)

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:43:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for(int i=0;i<X.size();i++) {
      |              ~^~~~~~~~~
fish.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for(int j=1;j<pts[i].size();j++) {
      |               ~^~~~~~~~~~~~~~
#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...