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;
typedef long long ll;
vector<vector<ll>> dp;
vector<pair<int,int>> aux;
ll sq(ll a){return a*a;}
void solve(int qtd,int l, int r, int p, int q){
int mid=(l+r)>>1, opt=-1;
for(int i=p; i<=min(q, mid-1); i++){
if(dp[qtd][mid]>dp[qtd-1][i]+sq(aux[mid].second-aux[i+1].first+1)-sq(aux[i].second-aux[i+1].first+1)*(aux[i].second>=aux[i+1].first)){
dp[qtd][mid]=dp[qtd-1][i]+sq(aux[mid].second-aux[i+1].first+1)-sq(aux[i].second-aux[i+1].first+1)*(aux[i].second>=aux[i+1].first);
opt=i;
}
}
if(l<mid)solve(qtd, l, mid-1, p, opt);
if(mid<r)solve(qtd, mid+1, r, opt, q);
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
aux.clear();
dp.resize(k+1);
for(int i=i; i<=k; i++)
dp.resize(n+1);
for(int i=0; i<n; i++){
aux.push_back({min(r[i], c[i]), -max(r[i], c[i])});
}
sort(aux.begin(), aux.end());
vector<pair<int,int>> temp;
temp.push_back({-1, -1});
for(auto cur:aux){
if(-cur.second>temp.back().second)temp.push_back({cur.first, -cur.second});
}
aux=temp;
for(int i=1; i<=k; i++){
for(int j=1; j<=aux.size(); j++){
dp[i][j]=1e18;
}
}
for(int i=1; i<aux.size(); i++){
dp[1][i]=sq(aux[i].second-aux[1].first+1);
}
for(int i=2; i<=min((int)aux.size()-1, k); i++)
solve(i, 1, aux.size()-1, 1, aux.size()-1);
return dp[min((int)aux.size()-1, k)][aux.size()-1];
}
Compilation message (stderr)
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:43:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int j=1; j<=aux.size(); j++){
| ~^~~~~~~~~~~~
aliens.cpp:48:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i=1; i<aux.size(); i++){
| ~^~~~~~~~~~~
aliens.cpp:26:2: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
26 | for(int i=i; i<=k; i++)
| ^~~
# | 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... |