이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#include "aliens.h"
#endif
struct Line {
long long a, b;
double x(const auto& rhs) { return 1.0 * (rhs.b - b) / (a - rhs.a); };
};
long long take_photos(int n, int m, int k, vector<int> row, vector<int> column) {
using pii = pair<int, int>;
vector<pii> p(n);
for (int i = 0; i < n; ++i) {
if (row[i] > column[i]) swap(row[i], column[i]);
p[i] = {row[i], column[i]};
}
auto dis = [&](pii a) { return abs(a.first - a.second) + 1; };
{ //sort_the_points
sort(p.begin(), p.end(), [&](const auto& a, const auto& b) {
return make_pair(a.first, -dis(a)) < make_pair(b.first, -dis(b));
});
vector<bool> mk(n, true);
pii point = {-1, -1};
for (int i = 0; i < n; ++i) {
if (point.first <= p[i].first && p[i].second <= point.second) mk[i] = false;
else point = p[i];
}
int cnt = 0;
for (int i = 0; i < n; ++i) {
cnt += mk[i];
if (mk[i]) p.push_back(p[i]);
}
p.erase(p.begin(), p.begin() + n);
p.push_back({-1, -1});
k = min(k, n = cnt);
vector<vector<long long>> f(k + 1, vector<long long>(n + 1, 1e15));
sort(p.begin(), p.end(), [&](const auto& a, const auto& b) { return a.first < b.first; });
}
auto cal = [&](int l, int r) {
long long val = abs(p[l].first - p[r].second) + 1; val *= val;
long long pre = max(0, p[l - 1].second - p[l].first + 1); pre *= pre;
return val - pre;
};
auto cost = [&](const auto& c) {
vector<long long> f(n + 1, 1'000'000'000'000'000), g(n + 1);
f[0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
long long val = f[j - 1] + cal(j, i) + c;
f[i] = min(f[i], val);
if (f[i] == val && g[j] + 1 < g[i]) g[i] = g[j] + 1;
}
}
return make_pair(f[n], g[n]);
};
long long l = 0, r = 1'000'000'000'000'000'000;
long long answer = 1'000'000'000'000'000'000;
while (l <= r) {
long long mid = l + r >> 1;
auto [val, cnt] = cost(mid);
if (cnt <= k) {
r = mid - 1;
answer = val - cnt * mid;
} else l = mid + 1;
}
return answer;
}
#ifdef LOCAL
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
int n, m, k; cin >> n >> m >> k;
vector<int> r(n), c(n);
for (int i = 0; i < n; ++i) cin >> r[i] >> c[i];
cout << take_photos(n, m, k, r, c) << "\n";
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp:11:18: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
11 | double x(const auto& rhs) { return 1.0 * (rhs.b - b) / (a - rhs.a); };
| ^~~~
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:71:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
71 | long long mid = l + r >> 1;
| ~~^~~
# | 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... |