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) (x) * (x)
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> cc) {
vpii intervals;
rep(i, n) {
if (r[i] > cc[i]) {
swap(r[i], cc[i]);
}
intervals.emplace_back(r[i], -cc[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);
}
}
while ((int)merged.size() > k) {
int besti = 0;
ll mincost = 1ll << 62;
rep(i, merged.size() - 1) {
int a, b, c, d;
tie(a, b) = merged[i];
tie(c, d) = merged[i + 1];
ll cost = sq(d - a + 1) - sq(b - a + 1) - sq(d - c + 1) + sq(max(0, b - c + 1));
if (cost < mincost) {
mincost = cost;
besti = i;
}
}
merged[besti].second = merged[besti + 1].second;
merged.erase(merged.begin() + besti + 1);
}
ll res = sq(merged[0].second - merged[0].first + 1);
rep(i, merged.size() - 1) {
int a, b, c, d;
tie(a, b) = merged[i];
tie(c, d) = merged[i + 1];
res += sq(d - c + 1) - sq(max(0, b - c + 1));
}
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... |