# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
786421 | LuoBo | Aliens (IOI16_aliens) | C++14 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
using namespace std;
const int MAXN=100010;
struct node {
int x, y;
} a[MAXN];
long long f[510][510];
long long min(long long x,long long y) { return x<y ? x : y ; }
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
for (int i=0;i<n;i++) {
if ( r[i]>c[i] ) { a[i+1].x=c[i]+1; a[i+1].y=r[i]+1; }
else { a[i+1].x=r[i]+1; a[i+1].y=c[i]+1; }
}
memset(f,0x3f3f3f3f,sizeof(f));
f[0][0]=0;
for (int i=1;i<=n;i++) {
for (int j=0;j<i;j++) {
for (int opt=1;opt<=k;opt++) {
f[i][opt]=min(f[i][opt],f[j][opt-1]+(a[i].x-a[j+1].x+1)*(a[i].x-a[j+1].x+1));
printf("%d %d %d %d\n",i ,j ,opt, (a[i].x-a[j+1].x+1)*(a[i].x-a[j+1].x+1));
}
}
}
return f[n][k];
}
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
std::vector<int> r(n), c(n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &r[i], &c[i]);
}
long long ans = take_photos(n, m, k, r, c);
printf("%lld\n", ans);
return 0;
}