This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "aliens.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const ll INF = 1e16 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
pii a[MAXN];
ll dp[2][MAXN];
void solve(int i, int l, int r, int oL, int oR) {
if (l > r) return;
int m = (l + r) / 2;
int nx = -1;
dp[i][m] = INF;
for (int j = oL; j <= min(m - 1, oR); j++) {
ll v1 = max(a[m].se, a[j + 1].se) - min(a[m].fi, a[j + 1].fi) + 1;
v1 = v1 * v1;
ll v2 = max(0, a[j].se - min(a[j + 1].fi, a[m].fi) + 1);
v2 = v2 * v2;
if (dp[i][m] > dp[i^1][j] + v1 - v2) {
nx = j;
dp[i][m] = dp[i^1][j] + v1 - v2;
}
}
solve(i, l, m - 1, oL, nx);
solve(i, m + 1, r, nx, oR);
}
ll take_photos(int n, int m, int k, vi r, vi c) {
vii tmp;
for (int i = 0; i < n; i++)
tmp.pb({min(r[i], c[i]), max(r[i], c[i])});
sort(tmp.begin(), tmp.end(), [](pii lhs, pii rhs) -> bool {
if (lhs.fi == rhs.fi)
return lhs.se > rhs.se;
return lhs.fi < rhs.fi;
});
int nn = 0;
a[0] = {-1, -1};
for (int i = 0; i < n; i++)
if (tmp[i].se > a[nn].se)
a[++nn] = tmp[i];
for (int i = 1; i <= nn; i++) {
ll v1 = max(a[i].se, a[1].se) - min(a[i].fi, a[1].fi) + 1;
dp[1][i] = v1 * v1;
}
for (int i = 2; i <= k; i++)
solve(i & 1, 1, nn, 0, nn - 1);
return dp[k&1][nn];
}
# | 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... |