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 n N
#define m M
#define k K
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
const int inf = 1e9 + 42;
int n, m, k;
vector<int> a, b;
int solve() {
vector<bool> v(1 + m, false);
v[0] = true;
for(int i = 0; i < n; i++) {
v[a[i] + 1] = true;
}
vector<int> prv(1 + m, 0);
for(int i = 1; i <= m; i++) {
if(v[i]) {
prv[i] = i;
} else {
prv[i] = prv[i - 1];
}
}
vector<vector<int> > dp(1 + m, vector<int> (1 + k, inf));
dp[0][0] = 0;
for(int j = 1; j <= k; j++) {
dp[0][j] = 0;
for(int i = 1; i <= m; i++) {
dp[i][j] = dp[i][j - 1];
for(int l = 0; l <= i; l++) {
dp[i][j] = min(dp[i][j], dp[prv[l]][j - 1] + (i - l) * (i - l));
}
dp[i][j] = min(dp[i][j], dp[prv[i]][j]);
}
}
int ans = inf;
for(int j = 0; j <= k; j++) {
ans = min(ans, dp[m][j]);
}
return ans;
}
#undef n
#undef m
#undef k
int take_photos(signed n, signed m, signed k, vector<signed> r, vector<signed> c) {
N = n;
M = m;
K = k;
a.assign(N, 0);
b.assign(N, 0);
for(int i = 0; i < N; i++) {
a[i] = r[i];
b[i] = c[i];
}
return solve();
}
# | 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... |