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 "aliens.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define X first
#define Y second
const int maxn = 1e3 + 5;
int n,m,k;
pii p[maxn];
int r[maxn], c[maxn];
ll dp[maxn][maxn];
bool cmp(pii x, pii y) {
if(x.X!=y.X) return x.X<y.X;
return x.Y>y.Y;
}
ll p2(ll x) {
return x*x;
}
void solve() {
for(int x=1;x<=n;x++) {
dp[x][0] = 1e13;
for(int t=1;t<=k;t++) {
dp[x][t] = 1e13;
for(int y=1;y<=x;y++) {
dp[x][t] = min(dp[x][t], dp[y-1][t-1] + p2(c[x]-r[y]) - p2(max(0,c[y-1]-r[y])));
}
// printf("dp %d %d = %lld\n",x,t,dp[x][t]);
}
}
}
long long take_photos(int N, int M, int K, std::vector<int> R, std::vector<int> C) {
n = N; m = M; k = K;
//prep
for(int i=0;i<n;i++) {
p[i] = {R[i],C[i]};
if(p[i].X>p[i].Y) swap(p[i].X,p[i].Y);
}
sort(p,p+n,cmp);
ll cur = -1, sz = 0;
for(int i=0;i<n;i++) {
if(p[i].Y<=cur) continue;
sz++;
r[sz] = p[i].X;
c[sz] = p[i].Y+1;
cur = p[i].Y;
}
n = sz;
solve();
return dp[n][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... |