제출 #347863

#제출 시각아이디문제언어결과실행 시간메모리
347863KerimAliens (IOI16_aliens)C++17
100 / 100
702 ms8036 KiB
#include "aliens.h" #include "bits/stdc++.h" #define MAXN 100009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cerr<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<ll,ll> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} bool cmp(PII x,PII y){ if(x.ff!=y.ff) return (x.ff<y.ff); return (x.ss>y.ss); } ll sqr(int x){ return x*1LL*x; } const ll B=1e18; ll dp[MAXN]; vector<ll>m,b; vector<int>ind; int sz,pos; double inter(int l1,int l2){ return double(b[l2]-b[l1])/double(m[l1]-m[l2]); } bool bad(int l1,int l2,int l3){ return inter(l1,l3)<inter(l1,l2); } void upd(ll x,ll y,int z){ m.pb(x);b.pb(y);ind.pb(z);sz++; while(sz>=3 and bad(sz-3,sz-2,sz-1)) m.erase(m.end()-2),b.erase(b.end()-2),ind.erase(ind.end()-2),sz--; } pair<ll,int> get(ll x){ assert(sz>0); umin(pos,sz-1); while(pos+1<sz and m[pos]*x+b[pos]>m[pos+1]*x+b[pos+1])pos++; return mp(m[pos]*x+b[pos],ind[pos]); } vector<pair<int,int> >arr,v; ll odp; int cnt(int n,ll lambda){ m.clear();b.clear();ind.clear();sz=pos=0; pair<ll,int> last=mp(0,0); for(int j=1;j<=n;j++){ int h=j-1; if(last.ff!=B) upd(-(arr[h+1].ff-1),sqr(arr[h+1].ff-1)+last.ff-sqr(max(0,arr[h].ss-arr[h+1].ff+1)),last.ss); last=get(2*arr[j].ss); if(last.ff!=B) last=mp(last.ff+lambda+sqr(arr[j].ss),last.ss+1); }odp=last.ff; return last.ss; } ll take_photos(int n, int M, int k, vector<int> r, vector<int> c) { for(int i=0;i<n;i++) v.pb(mp(min(r[i],c[i]),max(r[i],c[i]))); sort(all(v),cmp);arr.pb(mp(-1,-1)); for(int i=0;i<int(v.size());i++) if(arr.back().ss<v[i].ss) arr.pb(v[i]); n=int(arr.size())-1; umin(k,n); //for(int i=1;i<=n;i++) // printf("%d %d\n",arr[i].ff,arr[i].ss); ll st=0,en=ll(1e12); while(st+1<en){ ll mid=(st+en)>>1; debug(mid); debug(cnt(n,mid)); if(cnt(n,mid)>=k)st=mid; else en=mid; debug(odp); debug(odp-mid*cnt(n,mid)); wr } if(cnt(n,en)<=k)return odp-en*k; assert(cnt(n,st)<=k); return odp-st*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...