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<pair<int, int>> a = {{-1, -1}};
for (int i = 0; i < n; i++)
a.push_back({min(r[i], c[i]), max(r[i], c[i]) + 1});
sort(begin(a), end(a));
int cur = 0;
for (int i = 1; i <= n; i++)
if (a[i].first == a[cur].first) a[cur].second = a[i].second;
else if (a[i].second > a[cur].second) a[++cur] = a[i];
n = cur;
auto sqr = [&](int x)
{
return 1LL * x * x;
};
vector<vector<long long>> f(k + 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;
for (int jj = 0; jj < j; jj++)
{
long long cost = sqr(a[j].second - a[jj + 1].first);
if (a[jj].second > a[jj + 1].first)
cost -= sqr(a[jj].second - a[jj + 1].first);
f[i][j] = min(f[i][j], f[i - 1][jj] + cost);
}
}
long long ans = oo;
for (int i = 1; i <= k; i++)
ans = min(ans, f[i][n]);
return ans;
}
# | 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... |