#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, l, r) for (int i = (l); i < (r); ++i)
#define len(x) int(x.size())
long long take_photos(int n, int m, int K, std::vector<int> r, std::vector<int> c) {
vector<pair<int, int>> pts(n);
REP(i, 0, n) {
if (r[i] > c[i]) {
swap(r[i], c[i]);
}
pts[i] = make_pair(r[i], c[i]);
}
sort(ALL(pts));
{
vector<pair<int, int>> pts2;
REP(i, 0, n) {
if (i != n - 1 and pts[i].first == pts[i + 1].first) {
continue;
}
pts2.push_back(pts[i]);
}
pts = pts2;
n = len(pts);
}
{
vector<pair<int, int>> pts2;
int mx_c = -1;
REP(i, 0, n) {
if (pts[i].second <= mx_c) {
continue;
}
pts2.push_back(pts[i]);
mx_c = max(mx_c, pts[i].second);
}
pts = pts2;
n = len(pts);
}
vector<vector<ll>> dp(n + 1, vector<ll>(K + 1, 1ll << 60));
dp[0][0] = 0;
REP(i, 1, n + 1) {
REP(j, 0, i) {
ll diff = ll(pts[i - 1].second - pts[j].first + 1) * (pts[i - 1].second - pts[j].first + 1);
ll cost = diff - max(0ll, (j == 0 ? 0ll : (ll(pts[j - 1].second - pts[j].first + 1) * (pts[j - 1].second - pts[j].first + 1))));
REP(k, 0, K) {
dp[i][k + 1] = min(dp[i][k + 1], dp[j][k] + cost);
}
}
}
ll ans = 1ll << 60;
REP(i, 0, K + 1) {
ans = min(ans, dp[n][i]);
}
return ans;
}
Compilation message (stderr)
aliens.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
aliens_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |