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 <bits/stdc++.h>
using namespace std;
const int N=5e2+11;
const long long LINF = 1e18;
long long dp[N][N];
pair<long long,long long> a[N];
pair<long long,long long> b[N];
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
vector<pair<long long,long long>> vec;
for(int j=1;j<=n;j++){
dp[0][j]=1e18;
dp[j][0]=1e18;
}
for(int i=0;i<n;i++){
if(r[i]<c[i])swap(r[i],c[i]);
a[i+1]={r[i],c[i]};
}
sort(a+1,a+n+1);
pair<long long,long long> lst=a[n];
vec.push_back(lst);
for(int i=n-1;i>=1;i--){
if(a[i].second>=lst.second){
a[i]={-1,-1};
}
else{
lst=a[i];
vec.push_back(lst);
}
}
n=vec.size();
for(int i=0;i<n;i++){
a[i+1]=vec[i];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++){
long long ret=1e18;
for(int h=i;h>=1;h--){
long long u=(a[i].first-a[h].second+1)*(a[i].first-a[h].second+1) + dp[h-1][j-1];
long long f=0;
if(a[h-1].first>=a[h].second){
f = (a[h-1].first-a[h].second+1)*(a[h-1].first-a[h].second+1);
}
ret=min(ret,u-f);
}
dp[i][j]=ret;
}
}
// cout<<dp[0][0]<<" "<<dp[1][1]<<"\n";
long long ret=1e18;
for(int i=1;i<=k;i++){
ret=min(ret,dp[n][i]);
}
return ret;
}
# | 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... |