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;
#define int long long
#define ll long long
#define sqr(x) ((x)*(x))
using pii = pair<int, int>;
const int inf = 2e18;
long long take_photos(signed n, signed m, signed k, std::vector<signed> r, std::vector<signed> c) {
vector<pii> a(n);
for (int i = 0; i < n; i++) a[i] = {max(r[i], c[i]), min(r[i], c[i])};
sort(a.begin(), a.end(), [](pii a, pii b) {return a.first < b.first || a.first == b.first && a.second > b.second;});
vector<pii> st;
for (pii p : a) {
while (st.size() && st.back().second >= p.second)
st.pop_back();
st.push_back(p);
}
n = st.size();
k = min(k, n);
vector<int> x(n), y(n);
for (int i = 0; i < n; i++)
x[i] = st[i].first, y[i] = st[i].second;
vector<int> t(n, 0);
for (int i = 1; i < n; i++)
t[i] = sqr(max(0ll, x[i - 1] - y[i] + 1));
vector<vector<int>> d(n + 1, vector<int>(k + 1, inf));
for (int j = 0; j <= k; j++)
d[0][j] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
for (int f = 0; f < i; f++) {
ll c = d[f][j - 1];
c += sqr(x[i - 1] - y[f] + 1) - t[f];
if (c < d[i][j])
d[i][j] = c;
}
}
}
return d.back().back();
}
Compilation message (stderr)
aliens.cpp: In lambda function:
aliens.cpp:13:95: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
13 | sort(a.begin(), a.end(), [](pii a, pii b) {return a.first < b.first || a.first == b.first && a.second > b.second;});
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |