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 seg {
ll l, r;
bool operator < (const seg &p) const {
return l == p.l ? r > p.r : l < p.l;
}
};
#define sq(a) ((a) * (a))
ll take_photos(int n, int m, int kk, std::vector<int> r, std::vector<int> c) {
vector<seg> tmp, v;
for(int i=0; i<n; i++) {
if(r[i] > c[i])
swap(r[i], c[i]);
tmp.push_back({r[i], c[i]});
} sort(tmp.begin(), tmp.end());
for(int i=0; i<n; i++) {
if(v.size() && v.back().l <= tmp[i].l && tmp[i].r <= v.back().r) continue;
v.push_back(tmp[i]);
}
n = v.size();
ll dp[kk+1][n+1];
memset(dp, 0x3f, sizeof dp);
for(int i=1; i<=n; i++) {
dp[1][i] = sq(v[i-1].r - v[0].l + 1);
}
for(int k=2; k<=kk; k++) {
for(int i=1; i<=n; i++) {
for(int j=0; j<i; j++) {
ll len = sq(v[i-1].r - v[j].l + 1);
if(j && v[j].l <= v[j-1].r)
len -= sq(v[j-1].r - v[j].l+ 1);
dp[k][i] = min(dp[k][i], dp[k-1][j] + len);
}
}
}
ll Min = 1e18;
for(int k=1; k <= kk; k++) Min = min(Min, dp[k][n]);
return Min;
}
# | 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... |