Submission #424518

#TimeUsernameProblemLanguageResultExecution timeMemory
424518jainbot27Aliens (IOI16_aliens)C++17
0 / 100
2 ms2644 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define ar array #define all(x) x.begin(), x.end() #define siz(x) (int) x.size() #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define FOR(i, a, b) for(auto i=(a); i<(b); i++) #define ROF(i, a, b) for(auto i=(b)-1; i>=(a); i--) #define F0R(i, n) FOR(i, 0, n) #define R0F(i, n) ROF(i, 0, n) using ll=long long; using ld=long double; using pii=pair<int, int>; using pll=pair<ll, ll>; using vi=vector<int>; using vl=vector<ll>; using vpii=vector<pii>; template<class T> bool ckmin(T&a, const T&b) {return b<a?a=b,1:0;} template<class T> bool ckmax(T&a, const T&b) {return b>a?a=b,1:0;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int mxN=1e5+10; const int MOD=1e9+7; const ll infLL=1e18; const ld eps=1e-6; int n, m, k; vi r, c; vector<pair<ll, ll>> pts, pts2; struct line{ ll M, B; int idx; ll operator()(const ll&q){ return M*q+B; } line(){M=-1, B=-1, idx=-1;} line(ll m, ll b, int IDX):M(m), B(b), idx(IDX){} }; int L, R; // we can do convex hull in linear cause we only have x is decreasing order line A[mxN]; bool itersect(line P, line Q, line R){ if(pair<ll, ll>{(Q.B-P.B)*(Q.M-R.M), Q.idx}>pair<ll, ll>{(R.B-Q.B)*(P.M-Q.M), R.idx}) return 1; return 0; } void add(line V){ while(R-L>1&&itersect(A[R-2], A[R-1], V)) R--; A[R]=V; R++; } pair<ll, ll> qry(int X){ while(R-L>1&&A[L+1](X)<A[L](X)) L++; return {A[L](X), A[L].idx}; } pair<ll, ll> solve(ll x){ // cout << "Solve: " << x << "\n"; pair<ll, ll> dp={0, 0}; L=0, R=0; F0R(i, n){ ll A=max(i?pts[i-1].f-pts[i].s+1:0LL, 0LL); add(line(-2*pts[i].s, dp.f-A*A+pts[i].s*pts[i].s, dp.s));; dp=qry(pts[i].f+1); dp.s++; dp.f+=(pts[i].f+1)*(pts[i].f+1)+x; // cout << dp.f << ' ' << dp.s << "\n"; } return dp; } ll take_photos(int N, int M, int K, vi R, vi C){ n=N, m=M, k=K, r=R, c=C; F0R(i, n){ pts.pb({max(r[i], c[i]), min(r[i], c[i])}); } sort(all(pts)); F0R(i, n){ if(!pts2.empty()&&pts[i].s<=pts2.back().s) pts2.pop_back(); pts2.pb(pts[i]); } swap(pts, pts2); n=siz(pts); // for(auto [X, Y]:pts){ // cout << X << ' ' << Y << "\n"; // } ll lo=0, hi=m*m; while(lo+1<hi){ ll m=(lo+hi)/2; if(k>=solve(m).s) hi=m; else lo=m; } // cout << "LO: " << lo << ' ' << "HI: " << hi << "\n"; auto ans=solve(lo); return ans.f-lo*ans.s; }
#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...