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;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
#define ffor(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define fford(i, a, b) for (ll i = (a); i > (ll)(b); i--)
#define rep(i, n) ffor(i, 0, n)
#define forin(x, a) for (auto &x: a)
#define all(a) a.begin(), a.end()
#define sq(x) (ll)(x) * (x)
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
vpii intervals;
rep(i, n) {
if (r[i] > c[i]) {
swap(r[i], c[i]);
}
intervals.emplace_back(r[i], -c[i]);
}
sort(all(intervals));
vpii merged = {{intervals[0].first, -intervals[0].second}};
ffor(i, 1, intervals.size()) {
if (-intervals[i].second > merged.back().second) {
merged.emplace_back(intervals[i].first, -intervals[i].second);
}
}
vll dp(merged.size(), 1ll << 62);
rep(i, merged.size()) {
dp[i] = sq(merged[i].second - merged[0].first + 1);
}
ll res = dp.back();
ffor(used, 2, k + 1) {
vll ndp(merged.size(), 1ll << 62);
int start = 0;
ffor(i, used - 1, merged.size()) {
ffor(j, start, i) {
ll curr = dp[j] + sq(merged[i].second - merged[j + 1].first + 1) - sq(max(0, merged[j].second - merged[j + 1].first + 1));
if (curr < ndp[i]) {
ndp[i] = curr;
start = j;
}
}
}
dp = move(ndp);
res = min(res, dp.back());
}
return res;
}
# | 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... |