This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*input
*/
#include <bits/stdc++.h>
#include "aliens.h"
using namespace std;
namespace my_template {
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;
template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }
template<typename T>
void print(vector<T> vec, string name = "") {
cout << name;
for (auto u : vec)
cout << u << ' ';
cout << '\n';
}
}
using namespace my_template;
const int MOD = 1000000007;
const ll INF = 1e15;
const int MX = 100101;
int N, M, K;
vpl sk;
// ll eval(pl line, ll at) {
// return at * line.x + line.y;
// }
// bool bad(pl x, pl y, pl z) {
// return (ll)(x.y - y.y) * (z.x - x.x) >= (ll)(x.y - z.y) * (y.x - x.x);
// }
void daryk(vl &dp, vi &cnt, ll lambda) {
dp = vl(N + 1, INF);
cnt = vi(N + 1, 0);
dp[0] = 0;
for (int i = 1; i <= N; ++i)
{
for (int t = 0; t < i; ++t)
{
ll newVal = dp[t] + (sk[i].x - sk[t + 1].y + 1) * (sk[i].x - sk[t + 1].y + 1)
- max(sk[t].x - sk[t + 1].y + 1, 0ll) * max(sk[t].x - sk[t + 1].y + 1, 0ll) + lambda;
if (newVal < dp[i]) {
dp[i] = newVal;
cnt[i] = cnt[t] + 1;
}
}
}
dp[N] = dp[N] - cnt[N] * lambda;
}
// y < x
void sanitize(vi &r, vi &c) {
vpl temp;
for (int i = 0; i < N; ++i)
{
if (r[i] > c[i]) swap(r[i], c[i]);
temp.emplace_back(c[i], r[i]);
}
sort(temp.begin(), temp.end(), [](const pl & a, const pl & b) {
return a.x < b.x or (a.x == b.x and a.y > b.y);
});
for (int i = 0; i < N; ++i)
{
while (sk.size() and sk.back().y >= temp[i].y) sk.pop_back();
sk.push_back(temp[i]);
}
N = (int)sk.size();
sk.insert(sk.begin(), { -1, -1});
// for (auto u : sk) printf("%d %d\n", u.x, u.y);
}
ll take_photos(int n, int m, int k, vi r, vi c) {
N = n; M = m; K = k;
sanitize(r, c);
ll l = 0;
ll h = 1e14;
vl dp;
vi cnt;
while (l < h) {
ll mi = (l + h + 1) / 2;
daryk(dp, cnt, mi);
// printf("pries l = %lld, h = %lld, mi = %lld, cnt = %d, K = %lld\n", l, h, mi, cnt[N], K);
if (cnt[N] >= K)
l = mi;
else
h = mi - 1;
// printf("po l = %lld, h = %lld, mi = %lld\n", l, h, mi);
}
// printf("senas l = %d\n", l);
daryk(dp, cnt, l);
pl V1 = {dp[N], cnt[N]};
l++;
daryk(dp, cnt, l);
pl V2 = {dp[N], cnt[N]};
// printf("V1 = %lld %lld, V2 = %lld %lld\n", V1.x, V1.y, V2.x, V2.y);
if (V2.y == K or V1.y == V2.y) return V2.x;
return V1.x + (K - V1.y) * (V2.x - V1.x) / (V2.y - V1.y);
}
# | 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... |