#include "aliens.h"
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
typedef long long ll;
using namespace std;
vector<pair<ll,ll>> puntos;
ll dp[4005][4005],res=1e18;
// minima cantidad de cuadrantes que tomo hasta la pos i con k fotos
bool cmp(pair<ll,ll> x,pair<ll,ll> y){
if(x.first==y.first){
return x.second>y.second;
}
return x.first<y.first;
}
ll cuadrado(ll x){
return x*x;
}
ll take_photos(int n,int m,int k,vector<int> r,vector<int> c){
puntos.resize(n);
for(ll i=0;i<n;i++){
if(r[i]>c[i]){
swap(r[i],c[i]);
}
puntos[i]={r[i],c[i]};
}
sort(ALL(puntos),cmp);
vector<pair<ll,ll>> temp;
temp.push_back({-1,-1});
temp.push_back(puntos[0]);
for(ll i=1;i<n;i++){
if(puntos[i].second<=temp.back().second){
continue;
}
temp.push_back(puntos[i]);
}
puntos=temp;
n=puntos.size()-1;
for(ll i=0;i<=n;i++){
for(ll j=0;j<=k;j++){
dp[i][j]=1e18;
}
}
dp[0][0]=0;
for(ll i=1;i<=n;i++){
for(ll j=1;j<=k;j++){
// unir con los pasados;
for(ll l=1;l<=i;l++){
// unir del l al i
ll cant_cua=cuadrado(puntos[i].second-puntos[l].first+1);
// verificar si une con lo anterior;
ll limiteiz=puntos[l].first;
ll limitede=puntos[l-1].second;
if(limiteiz<=limitede){
cant_cua-=cuadrado(limitede-limiteiz+1);
}
dp[i][j]=min(dp[i][j],dp[l-1][j-1]+cant_cua);
}
}
}
for(int i=0;i<=k;i++){
res=min(res,dp[n][i]);
}
return res;
}
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... |