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 <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <utility>
//#include "aliens.h"
#define N 4040
#define K N
#define M 1001000
#define ll long long
#define ii std::pair<int,int>
ll dp[N][K];
ll over[N];
int line[M];
std::vector<ii> pt;
ll minl(ll a, ll b){
if(a == -1)return b;
if(b == -1)return a;
return a < b ? a:b;
};
ll take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c){
memset(dp,-1,sizeof(dp));
memset(over,0,sizeof(over));
memset(line,0,sizeof(line));
pt.clear();
for(int i = 0;i<n;i++){
if(r[i] >= c[i]){
line[c[i]] = std::max(line[c[i]],r[i]-c[i]+1);
}else if(r[i] < c[i]){
line[r[i]] = std::max(line[r[i]],c[i]-r[i]+1);
};
};
for(int i = 0;i<m;i++){
if(line[i])pt.push_back(ii(i,line[i]));
};
for(int i = 1;i<pt.size();i++){
if(over[i-1] > pt[i-1].second){
over[i] = over[i-1] + pt[i-1].first - pt[i].first;
}else{
over[i] = pt[i-1].second + pt[i-1].first - pt[i].first;
};
if(over[i] < 0)over[i] = 0;
//printf("pt: %d %d %d\n",pt[i].first,pt[i].second,over[i]);
};
//printf("%d %d %d %d\n",pt.size(),pt[0].first,pt[0].second,over[0]);
for(int i = 0;i<=k;i++)dp[0][i] = 0;
for(int i = 0;i<pt.size();i++){
for(int j = 0;j<k;j++){
if(dp[i][j] == -1)continue;
ll mx = pt[i].second;
for(int l = i+1;l<=pt.size();l++){
ll inlf = std::max(0ll,mx * mx - over[i]*over[i]);
dp[l][j+1] = minl(dp[l][j+1], dp[i][j] + inlf);
//printf("mx: %d dp: %d %d %d l: %d %d\n",mx,i,j,dp[i][j],l,dp[l][j+1]);
if(l < pt.size()){
mx = std::max(mx, (ll)pt[l].second + pt[l].first - pt[i].first);
};
};
};
};
ll mn = -1;
for(int i = 0;i<=k;i++){
//printf("%lld\n",dp[pt.size()][i]);
mn = minl(mn,dp[pt.size()][i]);
};
return mn;
};
Compilation message (stderr)
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:43:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1;i<pt.size();i++){
~^~~~~~~~~~
aliens.cpp:55:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i<pt.size();i++){
~^~~~~~~~~~
aliens.cpp:59:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int l = i+1;l<=pt.size();l++){
~^~~~~~~~~~~
aliens.cpp:63:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(l < pt.size()){
~~^~~~~~~~~~~
# | 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... |