# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
624107 | brucecccccc | Aliens (IOI16_aliens) | C++14 | 1 ms | 308 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;
typedef long long ll;
struct Photo {
int x, s;
};
struct Line {
ll m, c;
double intersectX(Line b) {
return (b.c - c) / (double) (m - b.m);
}
};
ll take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
vector<int> size(m, 0);
for (int i = 0; i < n; i++) {
if (r[i] <= c[i]) {
size[r[i]] = max(size[r[i]], c[i] - r[i] + 1);
} else {
size[c[i]] = max(size[c[i]], r[i] - c[i] + 1);
}
}
vector<Photo> photos;
vector<ll> add(1), st(1);
int prev = 0;
for (int i = 0; i < m; i++) {
if (size[i] > prev) {
prev = size[i];
if (photos.empty() || i >= photos.back().x + photos.back().s) {
st.push_back(0);
add.push_back(add.back() + 1ll * size[i] * size[i]);
} else {
ll start = photos.back().x + photos.back().s - i;
add.push_back(add.back() + 1ll * size[i] * size[i] - start * start);
st.push_back(start * start);
}
photos.push_back({ i, size[i] });
}
prev = max(0, prev - 1);
}
ll ans = add[photos.size()];
vector<vector<Line>> dp(k+1);
for (int i = 0; i < photos.size(); i++) {
for (int j = k; j >= 1; j--) {
auto& d = dp[j-1];
ll a = 0;
ll endPoint = photos[i].x + photos[i].s;
if (d.size() > 0) {
int l = 0, r = d.size() - 2;
while (l < r) {
int m = (l + r) / 2;
if (endPoint < d[m].intersectX(d[m+1])) r = m;
else l = m + 1;
}
auto val = d[l];
a = val.m * endPoint + val.c + 1ll * endPoint * endPoint - add[i+1];
}
// cout << i << ' ' << j << ' ' << d.size() << endl;
if (i == photos.size() - 1 && j == k) ans += a;
d = dp[j];
Line next = { -2 * photos[i].x, 1ll * photos[i].x * photos[i].x + st[i+1] + add[i] + a };
while (d.size() >= 2 && next.intersectX(d[d.size()-2]) < d[d.size()-2].intersectX(d.back()))
d.pop_back();
d.push_back(next);
}
}
return ans;
}
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... |