이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include "grader.cpp"
const ll inf = 1e16;
inline ll sq (ll x) {
return x * x;
}
ll take_photos (int n, int m, int k, vector <int> r, vector <int> c) {
array <ll, 2> a[n + 2];
for (int i = 0; i < n; i++) {
if (r[i] < c[i]) {
swap(r[i], c[i]);
}
c[i]++; r[i]++;
a[i + 1] = {c[i], r[i]};
}
sort(a + 1, a + n + 1, [&] (array <ll, 2> &x, array <ll, 2> &y) {
return x[0] == y[0] ? x[1] > y[1] : x[0] < y[0];
});
ll mx = 0;
array <ll, 2> b[n + 2];
int d = 0;
for (int i = 1; i <= n; i++) {
if (mx >= a[i][1]) {
continue;
}
b[++d] = a[i];
mx = a[i][1];
}
n = d;
ll dp[n + 2][k + 2] = {};
for (int i = 1; i <= n; i++) {
a[i] = b[i];
}
for (int i = n; i >= 1; i--) {
dp[i][0] = inf;
for (int j = 1; j <= k; j++) {
dp[i][j] = inf;
for (int l = i; l <= n; l++) {
if (l == n) {
dp[i][j] = min(dp[i][j], sq(a[l][1] - a[i][0] + 1));
} else {
dp[i][j] = min(dp[i][j], sq(a[l][1] - a[i][0] + 1) - sq(max(0ll, a[l][1] - a[l + 1][0] + 1)) + dp[l + 1][j - 1]);
}
}
}
}
return dp[1][k];
}
# | 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... |