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;
typedef long long ll;
const ll INF = (ll)1e18;
ll take_photos(int n, int m, int k, vector<int> ri, vector<int> ci) {
vector<pair<ll,ll>> points;
for (int i = 0; i < n; i++) points.push_back(make_pair(max(ci[i],ri[i]),min(ri[i],ci[i])));
sort(points.begin(),points.end());
vector<ll> r,c; //such that r_i < r_j, c_i < c_j
for (int i = 0; i < n; i++) {
while (r.size() > 0 && points[i].second <= r.back()) {
r.pop_back(); c.pop_back();
}
r.push_back(points[i].second); c.push_back(points[i].first);
}
n = r.size();
//for (int i = 0; i < n; i++) cout << r[i] << " " << c[i] << "\n";
vector<vector<ll>> dp(n+1, vector<ll> (k+1,INF)); //dp[i][k] = min squares covered over the first i points, using k segments
for (int u = 0; u <= k; u++) dp[0][u] = 0;
for (int i = 1; i <= n; i++) {
for (int u = 1; u <= k; u++) {
for (int j = 0; j < i; j++) {
ll overlap;
if (j == 0 || c[j-1] < r[j]) overlap = 0LL;
else overlap = (c[j-1]-r[j]+1)*(c[j-1]-r[j]+1);
ll area = (c[i-1]-r[j]+1)*(c[i-1]-r[j]+1);
dp[i][u] = min(dp[i][u],dp[j][u-1] + area - overlap);
}
}
}
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... |