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;
vector<pair<int, int>> p;
int L[100005], R[100005];
long long dp[505][505];
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++) p.push_back({min(r[i], c[i]), -max(r[i], c[i])});
sort(p.begin(), p.end());
int N=1, tmp_mx=-1;
for(int i=0; i<n; i++){
if(-p[i].second > tmp_mx){
L[N] = p[i].first, R[N] = -p[i].second;
tmp_mx = -p[i].second;
N++;
}
}
N--;
for(int i=1; i<=N; i++){
dp[i][0] = 1e18;
for(int j=1; j<=k; j++){
dp[i][j] = 1e18;
for(int x=1; x<=i; x++){
dp[i][j] = min(dp[i][j], dp[x-1][j-1]+1LL*(R[i]-L[x]+1)*(R[i]-L[x]+1)-(j > 1 ? 1LL*(R[x-1]-L[x]+1)*(R[x-1]-L[x]+1): 0LL));
}
}
}
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... |