| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1323283 | yswang | Aliens (IOI16_aliens) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define square(x) ((x)*(x))
int take_photo(int &n, int &m, int &k, vector<int> &r, vector<int> &c){
vector<pair<int, int>> ori(n); // 0-base
for (int i=0; i<n; i++) ori[i] = {min(r[i], c[i]), max(r[i], c[i])};
sort(ori.begin(), ori.end());
vector<pair<int, int>> stars{}; // 0-base
for (int i=0; i<n; i++){
if (stars.empty()) stars.push_back(ori[i]);
else if (stars.back().first==ori[i].first) stars.pop_back();
else if (stars.back().second < ori[i].second) stars.push_back(ori[i]);
}
n = stars.size();
vector<vector<int>> dp(k, vector<int>(n));
for (int i=0; i<k; i++){
for (int j=0; j<n; j++){
if (j<i) dp[i][j] = 0;
else if (i==0){
dp[i][j] = square(stars[j].second-stars[0].first+1);
}else{
dp[i][j] = m*m;
for (int h=i+1; h<=j; h++){
int area = square(stars[j].second-stars[h].first+1);
int over = (h>1) ? square(max(0LL, (stars[h-1].second-stars[h].first+1))) : 0;
dp[i][j] = min(dp[i][j], dp[i-1][h-1]+area-over);
}
}
}
}
return dp[k-1][n-1];
}
signed main(){
int n, m, k;
cin>>n>>m>>k;
vector<int> r(n), c(n);
for (int i=0; i<n; i++) cin>>r[i]>>c[i];
cout<<take_photo(n, m, k, r, c)<<'\n';
}
