이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <iostream>
#include <algorithm>
#define long long long
using namespace std;
const int N = 1e5 + 2;
const long INF = 1e18;
struct TPoint { long x, y; };
inline long sqr(long x) { return x * x; }
int n, m, k;
TPoint a[N];
void Reduce()
{
for (int i = 1; i <= n; ++i)
if (a[i].x > a[i].y) swap(a[i].x, a[i].y);
sort(a + 1, a + 1 + n, [](TPoint p, TPoint q) { return p.x < q.x || (p.x == q.x && p.y > q.y); });
int new_n = 1;
for (int i = 2; i <= n; ++i)
if (a[i].y > a[new_n].y) a[++new_n] = a[i];
n = new_n;
for (int i = 1; i <= n; ++i) ++a[i].y; // we add every column by 1
}
inline long Cost(int i, int j)
{
int pre_h = max(0LL, a[i - 1].y - a[i].x);
int cur_h = a[j].y - a[i].x;
return sqr(cur_h) - sqr(pre_h);
}
long f[2][N];
long Solve()
{
Reduce();
// for (int i = 1; i <= n; ++i) cerr << Cost(i, i) << ' ';
// cerr << '\n';
int cur = 1, pre = 0;
fill(f[cur] + 1, f[cur] + 1 + n, INF);
for (int i = 1; i <= k; ++i)
{
swap(cur, pre);
fill(f[cur], f[cur] + 1 + n, INF);
for (int j = 1; j <= n; ++j)
{
f[cur][j] = f[pre][j];
for (int l = 1; l <= j; ++l)
f[cur][j] = min(f[cur][j], f[pre][l - 1] + Cost(l, j));
}
}
return f[cur][n];
}
long take_photos(int _n, int _m, int _k, vector<int> _r, vector<int> _c) {
n = _n, m = _m, k = _k;
for (int i = 0; i < _n; ++i) a[i + 1] = {_r[i], _c[i]}; // we add column by 1
return Solve();
}
# | 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... |