제출 #69258

#제출 시각아이디문제언어결과실행 시간메모리
69258mr_bananaAliens (IOI16_aliens)C++17
4 / 100
3 ms860 KiB
#include "aliens.h" #include<bits/stdc++.h> using namespace std; const int MN=5000+10; long long inf; long long dp[MN][MN]; pair<int,int> p[MN]; long long sq(long long x){ return x*x; } int a[MN],b[MN]; int po,po1; double cross(int i,int j){ return 1.0*(a[i]-a[j])/(b[j]-b[i]); } int cht[MN]; void add(int i){ while(po>=2 && cross(i,cht[po-2])<cross(cht[po-1],cht[po-2])){ po--; } cht[po++]=i; } long long ans1(int x,int i){ return 1ll*a[i]*x+b[i]; } long long ans(int x){ int lo=0,hi=po; while(hi-lo>1){ int mid=(hi+lo)/2; if(cross(cht[mid],cht[mid-1])<x){ lo=mid; } else{ hi=mid; } } return ans1(x,cht[lo]); } long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) { inf=sq(m); for(int i=0;i<n;i++){ p[i]={min(r[i],c[i]),-max(r[i],c[i])-1}; } sort(p,p+n); int n1=unique(p,p+n)-p; n=0; int mx=-1; for(int i=0;i<n1;i++){ if(mx<-p[i].second){ p[n]={p[i].first,-p[i].second}; mx=p[n].second; n++; } } for(int i=0;i<n;i++){ a[i]=-2*p[i].first; if(i!=0){ dp[i][0]=inf; } b[i]=dp[i][0]+sq(p[i].first); } for(int j=1;j<=k;j++){ po=0,po1=0; add(0); for(int i=1;i<=n;i++){ dp[i][j]=sq(p[i-1].second)+ans(p[i-1].second); if(i<n){ b[i]=dp[i][j-1]+sq(p[i].first)-sq(max(0,p[i-1].second-p[i].first)); add(i); } } } return dp[n][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...