Submission #793251

#TimeUsernameProblemLanguageResultExecution timeMemory
793251alvingogoAliens (IOI16_aliens)C++14
4 / 100
1 ms340 KiB
#include "aliens.h" #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #define AquA cin.tie(0);ios_base::sync_with_stdio(0); #define fs first #define sc second #define p_q priority_queue #define sz(a) ((int)(a.size())) using namespace std; typedef long long ll; typedef pair<ll,ll> pll; vector<ll> v,nxt; int lst=0,mn; int n; bool check1(pll a,pll b,int c){ return a.fs*c+a.sc>=b.fs*c+b.sc; } bool check2(pll a,pll b,pll c){ return (b.sc-a.sc)*(b.fs-c.fs)<=(b.sc-c.sc)*(b.fs-a.fs); } ll get(ll p,bool x){ vector<pair<pll,int> > dq; vector<pll> dp(n); int l=0; dq.push_back({{1-mn,1ll*(1-mn)*(1-mn)},0}); //cout << p << ":\n"; for(int i=0;i<n;i++){ if(v[i]==n){ continue; } while(sz(dq)-l>1 && check1(dq[l].fs,dq[l+1].fs,2*i)){ l++; } dp[i].fs=2ll*i*dq[l].fs.fs+dq[l].fs.sc+1ll*i*i+p; dp[i].sc=dq[l].sc+1; ll xf=0; if(i>=nxt[i]){ xf=-(i-nxt[i]+1)*(i-nxt[i]+1); } ll a=(1-nxt[i]),b=dp[i].fs+(1ll*(1-nxt[i])*(1-nxt[i]))+xf; while(sz(dq)-l>1 && check2(dq[sz(dq)-1].fs,dq[sz(dq)-2].fs,{a,b})){ dq.pop_back(); } dq.push_back({{a,b},dp[i].sc}); /* cout << i << "\n"; cout << "from: " << dq[l].fs.fs << " " << dq[l].fs.sc << "\n"; for(int j=l;j<sz(dq);j++){ cout << dq[j].fs.fs << " " << dq[j].fs.sc << "\n"; } */ } /* for(int i=0;i<n;i++){ cout << dp[i].fs << " " << dp[i].sc << "\n"; } cout << "\n"; */ if(x==0){ return dp[lst].sc; } else{ return dp[lst].fs; } } ll take_photos(int N, int M, int k, vector<int> R, vector<int> C) { n=M; int m=N; v.resize(n+1,n); nxt.resize(n); for(int i=0;i<m;i++){ if(R[i]<C[i]){ swap(R[i],C[i]); } v[R[i]]=min(v[R[i]],(ll)C[i]); } mn=n; for(int i=n-1;i>=0;i--){ if(v[i]<mn){ nxt[i]=mn; if(mn==n){ lst=i; } mn=v[i]; } else{ v[i]=n; } } ll l=0,r=2e14; while(r>l){ ll mid=(l+r)/2; if(get(mid,0)<=k){ r=mid; } else{ l=mid+1; } } return get(l,1)-l*k; }
#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...