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 "aliens.h"
#include <iostream>
#include <algorithm>
using namespace std;
struct node{
int x,y;
}a[1000005];
long long int dp[50005][105],x[100005],y[100005];
bool cmp(node a,node b)
{
return a.x<b.x;
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
for(int i=0;i<n;i++)
{
a[i].x=r[i];
a[i].y=c[i];
if(a[i].y<a[i].x)
{
swap(a[i].x,a[i].y);
}
}
sort(a,a+n,cmp);
long long int cnt=1;
x[1]=a[0].x;
y[1]=a[0].y;
for(int i=1;i<n;i++)
{
if(a[i].x>x[cnt] && a[i].y>y[cnt])
{
cnt++;
x[cnt]=a[cnt].x;
y[cnt]=a[cnt].y;
}
else if(a[i].x==x[cnt] && a[i].y>y[cnt])
{
x[cnt]=a[cnt].x;
y[cnt]=a[cnt].y;
}
}
n=cnt;
for(int i=0;i<=n;i++)
{
for(int j=0;j<=k;j++)dp[i][j]=99999999999999999;
}
dp[0][0]=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=k;j++)
{
long long int nowy=y[i],nowx=x[i];
for(int l=i;l>=1;l--)
{
nowx=x[l];
dp[i][j]=min(dp[i][j],dp[l-1][j-1]+(nowy-nowx+1)*(nowy-nowx+1));
}
//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
}
}
return dp[n][min(n,k)];
}
# | 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... |