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>
#include "aliens.h"
#define ll long long
#define pb push_back
#define mp make_pair
#define P pair<ll,ll>
using namespace std;
const int maxn = 4100;
ll dp[maxn][maxn];
int n, m, k;
long long take_photos(int N, int M, int K, std::vector<int> r, std::vector<int> c) {
n = N; m = M; k = K;
vector<P>points;
for(int i=0;i<N;i++) {
points.pb(mp(r[i], c[i]));
}
points.pb(mp(-1, -1));
sort(points.begin(), points.end());
ll minv = INT_MAX, maxv = INT_MIN;
for(int i=1;i<=n;i++) {
minv = min(minv, min(points[i].first, points[i].second));
maxv = max(maxv, max(points[i].first, points[i].second));
dp[1][i] = (maxv - minv + 1) * (maxv - minv + 1);
}
for(int p=2;p<=k;p++) {
for(int i=1;i<=n;i++) {
dp[p][i] = LLONG_MAX;
ll minv = INT_MAX, maxv = INT_MIN;
for(int j=i;j>=1;j--) {
minv = min(minv, min(points[j].first, points[j].second));
maxv = max(maxv, max(points[j].first, points[j].second));
dp[p][i] = min(dp[p][i], dp[p-1][j-1] + (maxv-minv+1)*(maxv-minv+1));
}
}
}
return dp[k][n];
}
# | 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... |