이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
struct point {
int x, y;
bool operator == (const point &p) const {
return x == p.x && y == p.y;
}
bool operator < (const point &p) const {
return x == p.x ? y < p.y : x < p.x;
}
};
long long take_photos(int n, int m, int k, vector<int> R, vector<int> C) {
vector<point> f, r;
for (int i = 0; i < n; i++) {
if (R[i] > C[i]) swap(R[i], C[i]);
f.push_back({R[i], C[i]});
}
sort(f.begin(), f.end());
f.erase(unique(f.begin(), f.end()), f.end());
r.push_back(f[0]);
for (int i = 1; i < n; i++) {
if (r.back().x == f[i].x) {
r.pop_back();
r.push_back(f[i]);
} else if (f[i].y > r.back().y) {
r.push_back(f[i]);
}
}
n = r.size();
vector<vector<long long>> dp(k, vector<long long> (n, INF));
for (int i = 0; i < n; i++) dp[0][i] = (long long) (r[i].y - r[0].x + 1) * (r[i].y - r[0].x + 1);
auto cost = [&] (const int &i, const int &j) {
long long ext = (r[i].x < r[i - 1].y ? (long long) (r[i - 1].y - r[i].x) * (r[i - 1].y - r[i].x) : 0);
return (long long) (r[j].y - r[i].x + 1) * (r[j].y - r[i].x + 1) - ext;
};
for (int j = 1; j < k; j++)
for (int i = j; i < n; i++) {
dp[j][i] = dp[j - 1][i];
for (int k = 0; k < i; k++)
dp[j][i] = min(dp[j][i], dp[j - 1][k] + cost(k + 1, i));
}
long long ans = INF;
for (int i = 0; i < k; i++) ans = min(ans, dp[i][n - 1]);
return ans;
}
# | 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... |