| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 723842 | Pety | Aliens (IOI16_aliens) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
long long dp[502][502], cost[502][502];
long long take_photos(int n, int m, int k, vector<int>r, vector<int> c) {
vector<pair<int, int>>p;
p.push_back({-1, -1});
for (int i = 0; i < n; i++) {
if (r[i] > c[i])
swap(r[i], c[i]);
p.push_back({r[i], c[i]});
}
sort(p.begin(), p.end());
for (int i = 0; i <= n; i++)
for (int j = 0; j <= k; j++)
dp[i][j] = INF;
for (int j = 0; j <= k; j++)
dp[0][j] = 0;
for (int i = 1; i <= n; i++)
for (int j = i, mx = 0; j <= n; j++) {
mx = max(mx, p[j].second);
cost[i][j] = 1ll * (1ll * mx - p[i].first + 1) * (mx - p[i].first + 1);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
for (int t = 0; t < i; t++)
dp[i][j] = min(dp[t][j - 1] + cost[t + 1][i], dp[i][j]);
dp[i][j] = min(dp[i][j - 1], dp[i][j]);
}
}
return dp[n][k];
}
int main() {
int n, m, k;
assert(3 == scanf("%d %d %d", &n, &m, &k));
std::vector<int> r(n), c(n);
for (int i = 0; i < n; i++) {
assert(2 == scanf("%d %d", &r[i], &c[i]));
}
long long ans = take_photos(n, m, k, r, c);
printf("%lld\n", ans);
return 0;
}
/**
5 7 2
0 3
4 4
4 6
4 5
4 6
*/
