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<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define sep ' '
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1e6 + 10;
const ll INF = 1e18;
int n, m, k;
pll dp[MAXN];
ll f[MAXN];
inline ll pw(ll a) {
return a * a;
}
inline pll calc(ll lambda) {
vector<int> opts;
ll mx_f = -1;
for (int i = 0; i < m; i++) {
if (f[i] > mx_f) {
mx_f = f[i];
opts.push_back(i);
}
}
int ind = 0;
for (int e : opts) {
int len = f[e] - e + 1;
dp[ind] = {pw(len + e - opts.front()) + lambda, 1};
for (int ii = 0; ii < int(opts.size()); ii++) {
int e2 = opts[ii];
if (e2 >= e) break;
int tlen = len + (e - opts[ii + 1]);
int mn_cov = opts[ii + 1];
pll tmp = {dp[ii].X + pw(tlen) - (mn_cov > f[e2] ? 0 : pw(f[e2] - mn_cov + 1)) + lambda, dp[ii].Y + 1};
dp[ind] = min(dp[ind], tmp);
}
ind++;
}
return dp[int(opts.size()) - 1];
}
ll take_photos(int n_, int m_, int k_, vector<int> r_, vector<int> c_) {
fill(f, f + MAXN, -1);
n = n_, m = m_, k = k_;
for (int i = 0; i < n; i++) {
int x = r_[i], y = c_[i];
if (y < x) swap(x, y); // TODO: check
f[x] = max(f[x], ll(y));
}
ll l = 0, r = INF / n;
while (l < r) {
ll mid = (l + r) / 2;
if (calc(mid).Y > k) l = mid + 1;
else r = mid;
}
return calc(l).X - k * l;
}
# | 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... |