이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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
{
long double x;
ll a, b;
};
vector<node> hull;
void clean(vector<pair<int,int> > &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<int,int> > tmp;
int r = 0;
for(auto x:seg)
{
if(x.se>r)
tmp.pb(x);
r=max(r,x.se);
}
swap(seg,tmp);
}
long double getval(long double x, ll a, ll b)
{
return x*a+b;
}
long double inters(ll a1, ll b1, ll a2, ll b2)
{
return (long double)(b1-b2)/(a2-a1);
}
void addline(ll a, ll b)
{
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});
return;
}
hull.pop_back();
}
hull.pb({-2e9,a,b});
}
ll getmax(ll x)
{
auto t = *--upper_bound(hull.begin(),hull.end(),x,[](ll x, node t){return (x<t.x);});
return (ll)getval(x,t.a,t.b);
}
ll take_photos(int n, int m, int k, vector<int> r, vector<int> c)
{
vector<pair<int,int> > seg(n);
for(int i = 0;i<n;i++)
{
if(r[i]>c[i])
swap(r[i],c[i]);
seg[i]={r[i],c[i]};
}
clean(seg);
n=seg.size();
int coll[n];
coll[0]=0;
for(int i = 1,t;i<n;i++)
t=max(0,seg[i-1].se-seg[i].fi+1),
coll[i]=t*t;
vector<ll> dp(n+1), dp1(n+1);
for(int j = 1;j<=k;j++)
{
for(int i = 0;i<n;i++)
{
ll l = seg[i].fi, r = seg[i].se;
addline(-2*l,dp[i]-coll[i]+l*(l-2));
dp1[i+1]=getmax(r)+r*(r+2)+1;
}
swap(dp,dp1);
hull.clear();
}
return dp[n];
}
# | 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... |