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<bits/stdc++.h>
#include "aliens.h"
using namespace std;
using ll = long long;
ll INF = 1e16;
ll take_photos(int n, int m, int K, vector<int> r, vector<int> c) {
vector<pair<ll, ll>> a, b;
for(int i = 0; i < n; i++) {
if(r[i] > c[i]) swap(r[i], c[i]);
a.push_back({r[i], c[i]});
}
sort(a.begin(), a.end());
ll mx = -1;
b.push_back({-1, -1});
for(auto [r, c] : a) {
if(c <= mx) continue;
b.push_back({r, c});
mx = max(mx, c);
}
a = b;
n = (int)a.size() - 1;
vector<vector<ll>> dp(n + 1, vector<ll>(K + 1, INF));
dp[0][0] = 0;
for(int i = 1; i <= n; i++) {
for(int k = 1; k <= K; k++) {
for(int j = 0; j < i; j++) {
ll val = dp[j][k - 1] + (a[i].second - a[j + 1].first + 1) * (a[i].second - a[j + 1].first + 1);
if(a[j].second >= a[j + 1].first) val -= (a[j].second - a[j + 1].first + 1) * (a[j].second - a[j + 1].first + 1);
dp[i][k] = min(dp[i][k], val);
}
}
}
ll res = INF;
for(int k = 1; k <= K; k++)
res = min(res, dp[n][k]);
return res;
}
# | 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... |