# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
773597 | peteza | Aliens (IOI16_aliens) | C++14 | 1 ms | 212 KiB |
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;
using pii = pair<int, int>;
long long dp[4005][4005];
long long square(long long x) {
x = max(0ll, x);
return x*x;
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
std::vector<pii> points;
std::vector<pii> rps;
for(int i=0;i<n;i++) {
if(r[i] < c[i]) points.emplace_back(r[i], c[i]);
else points.emplace_back(c[i], r[i]);
}
sort(points.begin(), points.end(), [](pii a, pii b){return a.first < b.first || (a.first == b.first && a.second > b.second);});
int last = -1;
for(auto e:points) {
if(last == e.first) continue;
while(!rps.empty() && rps.back().second >= e.second) rps.pop_back();
if(rps.empty() || rps.back().second < e.second) rps.emplace_back(e);
last = e.first;
}
for(int i=0;i<rps.size();i++) dp[i][0] = square(rps[i].second-rps[0].first+1)/*, cout << dp[i][0] << ' '*/;
for(int j=1;j<k;j++) {
for(int i=j;i<rps.size();i++) {
dp[i][j] = 1000000000000000000ll;
//cout << "Calcing " << j << ' ' << i << '\n';
for(int k=j-1;k<i;k++) {
dp[i][j] = min(dp[i][j], dp[k][j-1] - square(rps[k].second-rps[k+1].first+1) + square(rps[i].second-rps[k+1].first+1));
}
}
}
return dp[rps.size()-1][k-1];
}
Compilation message (stderr)
# | 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... |