이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "aliens.h"
#define fi first
#define se second
using namespace std;
long long sqr(int x) {
return 1LL * x * x;
}
struct line {
int a;
long long b;
line(int _a, long long _b) : a(_a), b(_b) {}
long long at(int x) {
return 1LL * a * x + b;
}
double intersect(const line& oth) const {
return 1.0 * (b - oth.b) / (oth.a - a);
}
};
struct convex_hull {
deque<pair<line, int>> de;
void push(pair<line, int> cur) {
while (de.size() >= 2) {
double fit = de[de.size() - 2].fi.intersect(de[de.size() - 1].fi);
double sit = de[de.size() - 2].fi.intersect(cur.fi);
if (sit < fit && abs(sit - fit) >= 1E-6) {
de.pop_back();
} else {
break;
}
}
de.push_back(cur);
}
pair<long long, int> get_min(int x) {
while (de.size() >= 2 && de[0].fi.at(x) > de[1].fi.at(x)) {
de.pop_front();
}
int ans = de[0].se;
for (int i = 1; i < de.size() && de[i].fi.at(x) == de[0].fi.at(x); i++) {
ans = min(ans, de[i].se);
}
return {de[0].fi.at(x), ans + 1};
}
};
pair<long long, int> solve(vector<pair<int, int>>& pos, long long c) {
convex_hull cht;
cht.push({line(-2 * pos[0].fi, sqr(pos[0].fi)), 0});
for (int i = 0; i < (int)pos.size(); i++) {
pair<long long, int> mi = cht.get_min(pos[i].se);
mi.fi += c + 1LL * pos[i].se * pos[i].se;
if (i == (int)pos.size() - 1) {
return mi;
} else {
cht.push({line(-2 * pos[i + 1].fi, mi.fi + sqr(pos[i + 1].fi)), mi.se});
}
}
}
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
vector<pair<int, int>> ini(n), pos;
for (int i = 0; i < n; i++) {
ini[i] = (r[i] < c[i] ? make_pair(r[i], c[i]) : make_pair(c[i], r[i]));
}
sort(ini.begin(), ini.end(), [](const pair<int, int> &u, const pair<int, int> &v) {
return u.se < v.se || (u.se == v.se && u.fi > v.fi);
});
for (pair<int, int>& cur : ini) {
cur.fi--;
while (!pos.empty() && pos.back().fi >= cur.fi) {
pos.pop_back();
}
pos.push_back(cur);
}
k = min(k, (int)pos.size());
long long le = -1LL * m * m, ri = 1LL * m * m;
while (le <= ri) {
long long mi = (le + ri) / 2;
pair<long long, int> ans = solve(pos, mi);
if (ans.se <= k) {
ri = mi - 1;
} else {
le = mi + 1;
}
}
pair<long long, int> ans = solve(pos, le);
return ans.fi - 1LL * ans.se * le;
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In member function 'std::pair<long long int, int> convex_hull::get_min(int)':
aliens.cpp:47:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < de.size() && de[i].fi.at(x) == de[0].fi.at(x); i++) {
~~^~~~~~~~~~~
aliens.cpp: In function 'std::pair<long long int, int> solve(std::vector<std::pair<int, int> >&, long long int)':
aliens.cpp:66:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | 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... |