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 100100
#define M 1001000
#define ll long long
#define ii std::pair<int,int>
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(over,0,sizeof(over));
memset(line,0,sizeof(line));
std::vector<std::vector<ll>> dp(n+10,std::vector<ll>(k+10,-1));
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;
int iprev = 0;
ll mx = 0;
ll inlf,t1,t2;
for(int j = 1;j<=k;j++){
mx = 0;
for(int i = 1;i<=pt.size();i++){
mx = std::max(mx, (ll)pt[i-1].second + pt[i-1].first - pt[iprev].first);
inlf = std::max(0ll,mx * mx - over[iprev]*over[iprev]);
t1 = dp[iprev][j-1] + inlf;
inlf = std::max(0ll, pt[i-1].second * pt[i-1].second - over[i-1] * over[i-1]);
t2 = dp[i-1][j-1] + inlf;
if(t1 < t2 || dp[i-1][j-1] == -1){
dp[i][j] = t1;
}else{
dp[i][j] = t2;
iprev = i-1;
mx = pt[i-1].second;
};
};
};
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:41:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1;i<pt.size();i++){
~^~~~~~~~~~
aliens.cpp:58:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1;i<=pt.size();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... |