이 제출은 이전 버전의 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());
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);
}
pair<ll,int> godp(vector<pair<int,int> > &seg, ll c, vector<ll> &coll)
{
int n = seg.size();
vector<ll> dp(n+1,1e18), kc(n+1);
dp[0]=0;
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=i;j++)
{
ll dist = seg[i-1].se-seg[j-1].fi+1, dist2 = coll[j-1];
ll nw = dp[j-1]-dist2+dist*dist+c;
if(dp[i]>nw)
dp[i]=nw,
kc[i]=kc[j-1]+1;
else if(dp[i]==nw)
kc[i]=min(kc[i],kc[j-1]+1);
}
}
return {dp[n],kc[n]};
}
ll take_photos(int n, int m, int k, vector<int> row, vector<int> col)
{
vector<pair<int,int> > 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);
vector<ll> 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]=1ll*t*t;
ll l = 0, r = m*m;
while(l<r)
{
ll mid = (l+r)/2;
pair<ll,int> t = godp(seg,mid,coll);
if(t.se>k)
l=mid+1;
else
r=mid;
}
auto t = godp(seg,l,coll);
return t.fi-k*l;
}
# | 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... |