#include "aliens.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
const int MAXN = 4005;
const int MAXK = 4005;
int dp[MAXN][MAXK];
pair<int,int> v[MAXN],newv[MAXN];
long long take_photos(int32_t n, int32_t m, int32_t k, std::vector<int32_t> x, std::vector<int32_t> y)
{
for(int i=0;i<n;i++)
{
if(x[i] < y[i])
swap(x[i],y[i]);
v[i+1] = {x[i],y[i]};
}
sort(v+1,v+1+n);
int newn=0;
for(int i=1;i<=n;i++)
if(i==1 || v[i]!=v[i-1])
newv[++newn] = v[i];
n = newn;
for(int i=1;i<=n;i++)
v[i] = newv[i];
for(int i=1;i<=n;i++)
for(int j=0;j<=k;j++)
dp[i][j]=INF;
for(int j=0;j<=k;j++)
dp[0][j]=0;
v[0] = {-1,-1};
newn=0;
int cv=INF;
for(int i=n;i>0;i--)
{
if(v[i].second < cv)
{
newv[++newn] = v[i];
cv = v[i].second;
}
}
reverse(newv+1,newv+1+newn);
n = newn;
for(int i=1;i<=n;i++)
v[i] = newv[i];
k = min(k, n);
for(int i=1;i<=n;i++)
{
for(int cnt=1;cnt<=k;cnt++)
{
for(int u=i-1;u>=0;u--)
{
if(v[u+1].second > v[u].first)
{
dp[i][cnt] = min(dp[i][cnt], dp[u][cnt-1] + v[u+1].second*v[u+1].second - 2*v[u+1].second * (v[i].first+1) + v[i].first*(v[i].first+2) + 1);
}
else
{
//int newv = (v[i].first-v[u+1].second+1)*(v[i].first-v[u+1].second+1);
//newv -= (v[u].first-v[u+1].second+1)*(v[u].first-v[u+1].second+1);
dp[i][cnt] = min(dp[i][cnt], dp[u][cnt-1] + v[u+1].second*v[u+1].second - 2*v[u+1].second * (v[i].first+1) + v[i].first*(v[i].first+2) - v[u+1].second*v[u+1].second + 2*v[u+1].second * (v[u].first+1) - v[u].first*(v[u].first+2));
}
}
}
}
int mnm=INF;
for(int i=0;i<=k;i++)
mnm = min(mnm, dp[n][i]);
return mnm;
}
/*
5 7 2
0 3
4 4
4 6
4 5
4 6
output:
25
2 6 2
1 4
4 1
output:
16
*/
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... |