이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(v) ((int)(v).size())
typedef long long lint;
typedef pair<int,int> pii;
vector<pii>Vtmp,V;
lint sq(int L)
{
return 1ll*L*L;
}
int a[500004],b[500004];
struct Line{
lint a,b;
};
vector<Line>CHT[4004];
int piv[500004];
int N;
lint D[500004];
bool check1(Line A,Line B,Line C)
{
if((long double)(B.b-A.b)/(A.a-B.a) > (long double)(C.b-B.b)/(B.a-C.a))return 1;
else return 0;
}
bool check2(Line A,Line B,lint x)
{
if((B.b-A.b) < x*(A.a-B.a)) return 1;
else return 0;
}
void insert_line(int num,Line L)
{
while((int)CHT[num].size()>2 && check1(CHT[num][(int)CHT[num].size()-2],CHT[num][(int)CHT[num].size()-1],L)){
CHT[num].pop_back();
piv[num]=min(piv[num],(int)CHT[num].size()-1);
}
CHT[num].push_back(L);
}
lint gets(int num,lint x)
{
int p=piv[num],q=sz(CHT[num]),h;
while(p!=q-1)
{
h=(p+q)/2;
if(check2(CHT[num][h-1],CHT[num][h],x))p=h;
else q=h;
}
piv[num]=p;
return CHT[num][p].a*x+CHT[num][p].b;
}
lint take_photos(int n, int m, int K, std::vector<int> r, std::vector<int> c) {
for(int i=0;i<n;i++)
{
if(r[i]<c[i])swap(r[i],c[i]);
Vtmp.push_back({r[i],-c[i]});
}
sort(Vtmp.begin(),Vtmp.end());
int mini=1e9;
for(int i=(int)Vtmp.size()-1;i>=0;i--)
{
if(mini>-Vtmp[i].second)V.push_back({Vtmp[i].first,-Vtmp[i].second});
mini=min(mini,-Vtmp[i].second);
}
sort(V.begin(),V.end());
n=V.size();
for(int i=1;i<=n;i++)
{
a[i]=V[i-1].second;
b[i]=V[i-1].first+1;
}
insert_line(0,{-2*a[1],sq(a[1])});
K=min(K,n);
N=n;
for(int i=0;i<=K;i++)piv[i]=0;
for(int i=1;i<=n;i++)
{
for(int k=min(K,i);k>=1;k--)
{
D[k]=gets(k-1,b[i])+sq(b[i]);
if(i!=n)insert_line(k,{-2*a[i+1],D[k]+sq(a[i+1])-sq(b[i]-min(b[i],a[i+1]))});
}
}
lint ans=1e18;
for(int k=1;k<=K;k++)ans=min(ans,D[k]);
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... |