This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// moreflags=grader.cpp
// naive solution.
#include "aliens.h"
// 15
#include<algorithm>
#include<cstdint>
#include<climits>
#if not LOCAL
#define NDEBUG
#endif
#include<cassert>
long long take_photos(int n, int m, int numPhoto, std::vector<int> r, std::vector<int> c) {
std::vector<std::pair<int, int>> points(r.size());
for(int index=0; index<(int)r.size(); ++index)
points[index]=std::minmax({r[index], c[index]});
std::sort(begin(points), end(points),
[&](auto first, auto sec){return first.first!=sec.first ? first.first<sec.first: first.second>sec.second;
});
{ // keep only extreme points
auto out=points.begin()+1;
std::for_each(out, points.end(),[&](auto it){
assert(it.first>=out[-1].first);
if(it.second>out[-1].second){
assert(it.first>out[-1].first);
*out++=it;
}
});
points.erase(out, points.end());
}
r.clear(); c.clear(); n=-1;
auto const square=[&](int it)->int64_t{return (int64_t)it*it;};
std::vector<std::vector<int64_t>> value(points.size()+1, std::vector<int64_t>(numPhoto+1));
for(int pos=1; pos<=(int)points.size(); ++pos){
value[pos][0]=INT64_MAX/2;
for(int numPhoto=1; numPhoto<(int)value[pos].size(); ++numPhoto){
auto& cur=value[pos][numPhoto]=INT64_MAX/2;
for(int last=0; last<pos; ++last){
cur=std::min(cur, value[last][numPhoto-1]
+square(points[pos-1].second-points[last].first+1)
-square(last==0 ? 0: std::max(0, points[last-1].second-points[last].first+1))
);
}
}
}
return value[points.size()][numPhoto];
}
# | 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... |