Submission #1106879

#TimeUsernameProblemLanguageResultExecution timeMemory
1106879pit4hCatfish Farm (IOI22_fish)C++17
9 / 100
143 ms23880 KiB
#include "fish.h" #include<bits/stdc++.h> using namespace std; using ll=long long; using pi=pair<int,int>; using vi=vector<int>; #define mp make_pair #define eb emplace_back #define x first #define y second #define sz(x)int((x).size()) #define all(x)(x).begin(),(x).end() #define rep(i,a,b)for(int i=(a);i<(b);i++) #define per(i,a,b)for(int i=(b)-1;i>=(a);i--) bool ckmin(auto&a,auto b){return b<a?a=b,1:0;} bool ckmax(auto&a,auto b){return b>a?a=b,1:0;} #ifdef LOCAL auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.x<<", "<<p.y<<")";} auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto&e:x)o<<","+!i++<<e;return o<<"}";} #define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X); #else #define debug(...){} #endif struct Container { ll shift=0,best=0; void add(ll delta) { shift += delta; best += delta; } void ins(ll v) { ckmax(best, v); } ll get() { return best; } }; long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) { vector<vector<pi>> sweep(N + 2); rep(i,0,M) { sweep[X[i]+1].eb(Y[i],W[i]); } rep(i,0,N+2) { sweep[i].eb(N,0); sort(all(sweep[i])); } vector<vector<ll>> dp(N+2); vector<ll> best_dp(N+2); rep(i,0,N+2) { dp[i].resize(sz(sweep[i])); } ll ans = 0; rep(i,1,N+1) { debug(i); int ptr_l=0,ptr_r=0; ll sum_l=0,sum_cur=0,sum_r=0; Container best_l; rep(j,0,sz(sweep[i])) { auto [y,w] = sweep[i][j]; while (ptr_l < sz(sweep[i-1]) && sweep[i-1][ptr_l].x < y) { sum_l+=sweep[i-1][ptr_l].y; best_l.ins(dp[i-1][ptr_l]); best_l.add(sweep[i-1][ptr_l].y); ptr_l++; } while (ptr_r < sz(sweep[i+1]) && sweep[i+1][ptr_r].x < y) { sum_r+=sweep[i+1][ptr_r].y; ptr_r++; } ckmax(dp[i][j], best_l.get()); ckmax(dp[i+1][ptr_r], best_l.get() + sum_r); // cur takes from left and right ckmax(dp[i+1][ptr_r], best_dp[i-1] + sum_r); // prev does not take any from column i ckmax(dp[i+1][ptr_r], best_dp[i] + sum_r - sum_cur); // prev takes unlimited amount from column i sum_cur+=w; } rep(s,0,2) { rep(j,0,sz(sweep[i-s])) { ckmax(best_dp[i-s], dp[i-s][j]); } } debug(dp); } rep(i,0,N+2) { rep(j,0,sz(dp[i])) { ckmax(ans, dp[i][j]); } } return ans; }

Compilation message (stderr)

fish.cpp:16:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   16 | bool ckmin(auto&a,auto b){return b<a?a=b,1:0;}
      |            ^~~~
fish.cpp:16:19: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   16 | bool ckmin(auto&a,auto b){return b<a?a=b,1:0;}
      |                   ^~~~
fish.cpp:17:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   17 | bool ckmax(auto&a,auto b){return b>a?a=b,1:0;}
      |            ^~~~
fish.cpp:17:19: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   17 | bool ckmax(auto&a,auto b){return b>a?a=b,1:0;}
      |                   ^~~~
#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...