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;
using lint = long long;
using pint = pair<int, int>;
#define x first
#define y second
const int maxn = 100004;
const lint inf = (lint)4.29e11;
vector<pint> ra, a;
lint m[maxn];
int p[maxn];
lint sq(int x) { return x*(lint)x; }
lint cost(int x, int y) {
lint ret = sq(a[y].y - a[x+1].x + 1);
if (x>=0 and a[x].y >= a[x+1].x) ret -= sq(a[x].y - a[x+1].x + 1);
ret *= 2;
if (x>=0) ret += m[x];
return ret;
}
int f(lint k) {
fill(m, m+maxn, -inf);
for (int i=0, j=-1; i<a.size(); i++) {
while (j+1<i and cost(j, i) >= cost(j+1, i)) j++;
m[i] = cost(j, i) + k;
p[i] = j;
}
int ret = 0;
for (int i=a.size()-1; ~i; i=p[i]) ret++;
return ret;
}
lint take_photos(int n, int M, int k, vector<int> R, vector<int> c) {
for (int i=0; i<n; i++) ra.emplace_back(min(R[i], c[i]), max(R[i], c[i]));
sort(ra.begin(), ra.end(), [](pint a, pint b) { return a.x < b.x or (a.x == b.x and a.y > b.y); });
int mx = -1;
for (pint& i : ra) {
if (i.y <= mx) continue;
mx = i.y;
a.push_back(i);
}
lint l = 0, r = inf;
while (l+1<r) {
lint m = (l+r) / 2;
if (f(m) > k) l = m;
else r = m;
}
k = f(r);
return (m[a.size()-1] - r * k) / 2;
}
Compilation message (stderr)
aliens.cpp: In function 'int f(lint)':
aliens.cpp:26:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0, j=-1; i<a.size(); i++) {
~^~~~~~~~~
# | 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... |