# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
469046 | flashmt | Aliens (IOI16_aliens) | C++17 | 0 ms | 0 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 <bits/stdc++.h>
using namespace std;
const long long oo = 1LL << 60;
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c)
{
vector<int> id(n);
for (int i = 0; i < n; i++)
{
if (r[i] > c[i])
swap(r[i], c[i]);
id[i] = i;
}
sort(begin(id), end(id), [&](int u, int v) { return r[u] + c[u] < r[v] + c[v]; });
vector<vector<long long>> f(n + 1, vector<long long>(n + 1, oo));
f[0][0] = 0;
for (int i = 1; i <= k; i++)
for (int j = 1; j <= n; j++)
{
f[i][j] = oo;
int minX = n, maxY = -1;
for (int jj = j - 1; jj >= 0; jj--)
{
minX = min(minX, r[id[jj]]);
maxY = max(maxY, c[id[jj]]);
int area = (maxY - minX + 1LL) * (maxY - minX + 1);
f[i][j] = min(f[i][j], f[i - 1][jj] + area);
}
}
long long ans = oo;
for (int i = 1; i <= k; i++)
ans = min(ans, f[i][n]);
return ans;
}
int main() {
int n, m, k;
assert(3 == scanf("%d %d %d", &n, &m, &k));
std::vector<int> r(n), c(n);
for (int i = 0; i < n; i++) {
assert(2 == scanf("%d %d", &r[i], &c[i]));
}
long long ans = take_photos(n, m, k, r, c);
cout << ans << endl;
}