This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "aliens.h"
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define ld long double
#define en cin.close();return 0;
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct node
{
ld x, a, b;
ll k;
};
deque<node> hull;
void clean(vector<pair<ld,ld> > &seg)
{
sort(seg.begin(),seg.end(),[](auto &i, auto &j)
{
if(i.fi==j.fi)
return (i.se>j.se);
return (i.fi<j.fi);
});
vector<pair<ld,ld> > tmp;
ld r = 0;
for(auto x:seg)
{
if(x.se>r)
tmp.pb(x);
r=max(r,x.se);
}
swap(seg,tmp);
}
ld getval(ld x, ld a, ld b)
{
return x*a+b;
}
ld inters(ld a1, ld b1, ld a2, ld b2)
{
return (b1-b2)/(a2-a1);
}
void addline(ld a, ld b, ll k)
{
while(!hull.empty())
{
auto t = hull.back();
if(getval(t.x,a,b)>getval(t.x,t.a,t.b))
{
if(t.a-a)
hull.pb({inters(t.a,t.b,a,b),a,b,k});
return;
}
hull.pop_back();
}
hull.pb({-2e9,a,b,k});
}
pair<ld,int> getmax(ld x)
{
while(hull.size()>1&&hull[1].x<=x)
hull.pop_front();
auto t = hull[0];
return {getval(x,t.a,t.b),t.k};
}
ll take_photos(int n, int m, int k, vector<int> row, vector<int> col)
{
vector<pair<ld,ld> > seg(n);
for(int i = 0;i<n;i++)
{
if(row[i]>col[i])
swap(row[i],col[i]);
seg[i]={row[i]+1,col[i]+1};
}
clean(seg);
n=seg.size();
k=min(k,n);
ld coll[n];
coll[0]=0;
for(int i = 1,t;i<n;i++)
t=max((ld)0,seg[i-1].se-seg[i].fi+1),
coll[i]=t*t;
ld l = 0, r = m*m;
vector<ld> dp(n+1), kc(n+1);
while(kc[n]!=k&&r-l>1e-18)
{
ld mid = (l+r)/2;
for(int i = 0;i<n;i++)
{
ld l = seg[i].fi, r = seg[i].se;
addline(-2*l,dp[i]-coll[i]+l*(l-2),kc[i]+1);
auto t = getmax(r);
dp[i+1]=t.fi+r*(r+2)+1+mid;
kc[i+1]=t.se;
}
if(kc[n]>k)
l=mid;
else
r=mid;
hull.clear();
}
return round(dp[n]-kc[n]*r);
}
# | 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... |