This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "aliens.h"
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << '\n';
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MAXN = (int)4e3 + 5;
const int INF = (int)1e9;
const ll LINF = (ll)1e15;
ll dp[MAXN][MAXN];
pii arr[MAXN];
int n, m, k;
bool cmp(pii a, pii b) {
if (a.fi == b.fi) {
return a.se > b.se;
}
return a.fi < b.fi;
}
void resolveOverlaps() {
sort(arr + 1, arr + n + 1, cmp);
int lim = 0, nn = 0;
for (int i = 1; i <= n; ++i) {
if (arr[i].se > lim) {
arr[++nn] = arr[i];
lim = arr[i].se;
}
}
n = nn;
}
ll f(int a, int b) {
int len = max(0, b - a + 1);
return len * 1ll * len;
}
ll solve() {
for (int i = 1; i <= n; ++i) {
if (arr[i].fi > arr[i].se) {
swap(arr[i].fi, arr[i].se);
}
}
resolveOverlaps();
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= k; ++j) {
dp[i][j] = LINF;
}
}
for (int i = 1; i <= n; ++i) {
for (int t = 1; t <= k; ++t) {
for (int j = 1; j <= i; ++j) {
dp[i][t] = min(dp[i][t], dp[j - 1][t - 1] + f(arr[j].fi, arr[i].se) - f(arr[j].fi, arr[j - 1].se));
}
}
}
return dp[n][k];
}
ll take_photos(int _n, int _m, int _k, vector<int> r, vector<int> c) {
n = _n;
m = _m;
k = _k;
for (int i = 1; i <= n; ++i) {
arr[i] = mp(r[i - 1] + 1, c[i - 1] + 1);
}
return solve();
}
# | 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... |