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 int
#define F first
#define S second
#define sz(x) (ll)x.size()
#define pb push_back
#define INF 1000000000000000000
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
void printVct(vi &v){
for (ll i= 0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
#define N 501
long long dp[N+1][N+1];
vector <long long> v;
ll n;
long long solve(ll u, ll k){
if (u >= n) return 0;
if (k <= 0) return INF;
if (dp[u][k] != -1) return dp[u][k];
long long ans = INF;
for (ll i =u+1; i<=n; i++){
long long d = (v[i-1] - v[u] + 1LL);
ans = min(ans, solve(i, k-1) + d * d);
}
return dp[u][k] = ans;
}
long long take_photos(int nn, int m, int k, vector<int> r, vector<int> c) {
for (ll i =0; i<=N; i++){
for (ll j = 0; j<=N; j++){
dp[i][j] = -1;
}
}
sort(r.begin(), r.end());
v.pb(r[0]);
for (ll i =1; i<nn; i++){
if (v.back() != r[i]){
v.pb(r[i]);
}
}
n = sz(v);
long long ans = solve(0, min(k,n));
return ans;
}
/*
4 7 3
1 1
2 2
4 4
6 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... |