#include"aliens.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN=5005;
const long long INF=1e18;
long long dp[MAXN][MAXN];
long long take_photos(int n,int m,int k,vector<int> r,vector<int> c)
{
vector< pair<int,int> > vi;
for(int i=0;i<n;i++) vi.push_back({min(r[i],c[i]),max(r[i],c[i])});
sort(vi.begin(),vi.end());
vector< pair<int,int> > vv;
vv.push_back(vi[0]);
for(int i=1;i<n;i++)
{
if(vv.back().first==vi[i].first) vv.pop_back(),vv.push_back(vi[i]);
else if(vv.back().second<vi[i].second) vv.push_back(vi[i]);
}
n=vv.size(),k=min(k,n);
for(int i=0;i<=k;i++) for(int j=0;j<=n;j++) dp[i][j]=INF;
dp[0][0]=0;
for(int i=1;i<=k;i++)
{
for(int j=i;j<=n;j++) for(int k=i-1;k<j;k++)
if(k==0)dp[i][j]=min(dp[i][j],dp[i-1][k]+1LL*(vv[j-1].second-vv[k].first+1)*(vv[j-1].second-vv[k].first+1));
else dp[i][j]=min(dp[i][j],dp[i-1][k]+1LL*(vv[j-1].second-vv[k].first+1)*(vv[j-1].second-vv[k].first+1)-1LL*max(0,vv[k-1].second-vv[k].first+1)*max(0,vv[k-1].second-vv[k].first+1));
}
return dp[k][n];
}
Compilation message (stderr)
aliens.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
aliens_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~| # | 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... |