#include<iostream>
#include<vector>
#include<algorithm>
#include<assert.h>
using namespace std;
const long long MAXN = 1e4+7;
const long long INF = 1e18;
pair<long long, long long> tt[MAXN];
vector<pair<long long, long long> > a;
long long dp[MAXN][MAXN], n, m;
bool cmp(pair<long long, long long> a1, pair<long long, long long> b1)
{
if(a1.first < b1.first) return true;
if(a1.first > b1.first) return false;
if(a1.second > b1.second) return true;
return false;
}
long long take_photos(int nn, int mm, int k, vector<int> r, vector<int> c)
{
n = nn;
m = mm;
for(long long i = 1; i <= n; i++)
{
tt[i].first = min(c[i-1], r[i-1]);
tt[i].second = max(c[i-1], r[i-1]);
}
sort(tt+1, tt+n+1, cmp);
long long maxi = -1;
for(long long i = 1; i <= n; i++)
{
if(tt[i].second > maxi)
{
maxi = tt[i].second;
a.push_back(tt[i]);
}
}
//cout<<a.size()<<"\n";
//dp[n][k] = min{dp[p][k-1]+(r[n]-l[p+1])^2-max(0, r[p]-l[p+1])^2};
for(long long i = 0; i < a.size(); i++)
{
dp[i][1] = (a[i].second-a[0].first+1)*(a[i].second-a[0].first+1);
}
for(long long i = 1; i <= k; i++)
{
dp[0][i] = (a[0].second-a[0].first+1)*(a[0].second-a[0].first+1);
}
for(long long i = 2; i <= k; i++)
{
for(long long j = 1; j < a.size(); j++)
{
long long mini = INF;
for(long long jj = 0; jj < j; jj++)
{
long long ss = max(0LL, a[jj].second-a[jj+1].first+1);
//cout<<i<<" "<<j<<" "<<jj<<" "<<dp[jj][i-1]+(a[j].second-a[jj+1].first+1)*(a[j].second-a[jj+1].first+1)-ss*ss<<"\n";
mini = min(mini, dp[jj][i-1]+(a[j].second-a[jj+1].first+1)*(a[j].second-a[jj+1].first+1)-ss*ss);
}
dp[j][i] = mini;
}
}
/*for(long long i = 0; i < a.size(); i++)
{
for(long long j = 1; j <= k; j++)
{
cout<<dp[i][j]<<" ";
}
cout<<"\n";
}*/
long long sz = a.size()-1;
return dp[sz][k];
}
/*
5 7 2
0 3
4 4
4 6
4 5
4 6
*/
/*long long main()
{
return 0;
}*/
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... |