This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//O(n^2 k)
#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 D[4004][4004];
lint sq(int L)
{
return 1ll*L*L;
}
int a[100004],b[100004];
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=sz(Vtmp)-1;i>=0;i--)
{
if(mini>Vtmp[i].first)V.push_back({Vtmp[i].first,-Vtmp[i].second});
mini=min(mini,-Vtmp[i].second);
}
sort(V.begin(),V.end());
n=sz(V);
for(int i=1;i<=n;i++)
{
a[i]=V[i-1].second+1;
b[i]=V[i-1].first+1;
}
for(int i=0;i<=n;i++)for(int k=0;k<=K;k++)D[i][k]=1e18;
D[0][0]=0;
for(int i=1;i<=n;i++)
{
for(int k=1;k<=i && k<=K;k++)
{
D[i][k]=1e18;
for(int j=0;j<i;j++)
{
D[i][k]=min(D[i][k],D[j][k-1]+sq(b[i]-a[j+1]+1)-sq(b[j]-min(b[j],a[j+1]-1)));
}
}
}
lint ans=1e18;
for(int k=1;k<=K;k++)ans=min(ans,D[n][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... |