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 pb push_back
#define X first
#define Y second
#define mp make_pair
typedef pair <int, int> pii;
typedef long long ll;
const int N=505;
const int INF=0x3f3f3f3f;
const ll MAX=(ll)INF*INF;
vector <pii> v, vec;
ll dp[N][N];
int cmp1(pii a, pii b) {
if (a.X==b.X) return a.Y>b.Y;
return a.X<b.X;
}
long long take_photos(int n, int m, int k, vector<int> rr, vector<int> cc) {
for (int i=0; i<n; ++i) {
if (rr[i]>cc[i]) swap(rr[i], cc[i]);
vec.pb(mp(rr[i], cc[i]));
}
sort(vec.begin(), vec.end(), cmp1);
int maxi=-1;
for (int i=0; i<n; ++i) {
if (maxi>=vec[i].Y) continue;
maxi=vec[i].Y;
v.pb(vec[i]);
// printf("dodajem [%d %d]\n", vec[i].X, vec[i].Y);
}
n=v.size();
v.insert(v.begin(), mp(-1, -1));
memset(dp, 0, sizeof dp);
for (int i=1; i<=n; ++i) {
dp[i][0]=MAX;
for (int j=1; j<=k; ++j) {
dp[i][j]=MAX;
for (int l=0; l<i; ++l) {
ll curr=dp[l][j-1]+(ll)(v[i].Y-v[l+1].X+1)*(v[i].Y-v[l+1].X+1);
ll presj=max(0LL, (ll)(v[l].Y-v[l+1].X+1));
dp[i][j]=min(dp[i][j], curr-presj*presj);
}
// printf("i: %d, j: %d, dp: %lld\n", i, j, dp[i][j]);
}
}
return dp[n][k];
}
/*
2 6 2
1 4
4 1
2 9 1
0 0
5 5
5 7 2
0 3
4 4
4 6
4 5
4 6
*/
# | 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... |