이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef pair<long long,long long> pp;
pp a[50005];
long long dp[50005];
pair<pp,int> s[2][50005];
int nn;
pp aa[50005];
long long c[50005];
inline long double cr(pp x,pp y){
if(x.f==y.f)return 0;
return (long double)(y.s-x.s)/(long double)(x.f-y.f);
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
long long ans;
int i,j;
for(i=1 ; i<=n ; i++){
a[i]={r[i-1],c[i-1]};
if(a[i].s<a[i].f)swap(a[i].f,a[i].s);
}
sort(a+1,a+n+1);
j=0;
a[0].f=-1;
a[0].s=-1;
a[n+1].f=-1;
for(i=1 ; i<=n ; i++){
if(a[i].s<=a[j].s || a[i].f==a[i+1].f);
else{
aa[++nn]=a[i];
j=i;
}
}
n=nn;
/// cout<<n<<endl;
int t=0;
for(i=1 ; i<=n ; i++){
dp[i]=(aa[i].s-aa[1].f+1)*(aa[i].s-aa[1].f+1);
c[i]=aa[i].f*aa[i].f-max((long long)0,aa[i-1].s-aa[i].f+1)*max((long long)0,aa[i-1].s-aa[i].f+1);
c[1]=aa[1].f*aa[1].f;
while(t>=2 && cr(s[1][t].f,s[1][t-1].f)>=cr(s[1][t-1].f,{-aa[i].f,dp[i-1]+c[i]}))t--;
if(t==1 && s[1][t].f.s>=dp[i-1]+c[i])t--;
s[1][++t]={{-aa[i].f,dp[i-1]+c[i]},i};
/// cout<<t<<"!@"<<endl;
}
///cout<<cr(s[1][2].f,s[1][1].f)<<endl;
int tt;
ans=dp[n];
for(int l=2 ; l<=k ; l++){
j=1;
tt=0;
for(i=l ; i<=n ; i++){
while(s[1][j+1].s<=i && j<t && cr(s[1][j].f,s[1][j+1].f)<2*(aa[i].s+1))j++;
dp[i]=(aa[i].s+1)*(aa[i].s+1)+s[1][j].f.s+2*s[1][j].f.f*(aa[i].s+1);
pair<pp,int> w={{-aa[i].f,c[i]+dp[i-1]},i};
while(tt>=2 && cr(s[0][tt].f,s[0][tt-1].f)>=cr(s[0][tt-1].f,w.f))tt--;
if(tt==1 && s[0][tt].f.s>=w.f.s)tt--;
s[0][++tt]=w;
}
for(i=1 ; i<=tt ; i++)s[1][i]=s[0][i];
if(l<=n)
ans=min(dp[n],ans);
t=tt;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |