이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "aliens.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e5 + 10;
struct Line {
long long a, b;
int t;
long long operator() (int x) {
return a * x + b;
}
};
vector <Line> convex;
int pointer;
int bad(const Line &L1, const Line &L2, const Line &L3) {
return 1.0L * (L2.b - L1.b) / (L1.a - L2.a) >= 1.0L * (L3.b - L1.b) / (L1.a - L3.a);
}
void add(Line L) {
while (convex.size() >= 2 && bad(convex.end()[-2], convex.back(), L)) convex.pop_back();
convex.push_back(L);
pointer = min(pointer, (int)convex.size() - 1);
}
pair <long long, int> get(int x) {
if (convex.empty()) return {1e18, 0};
while (pointer < convex.size() - 1 && convex[pointer](x) > convex[pointer + 1](x)) ++pointer;
return {convex[pointer](x), convex[pointer].t};
}
vector <pair <int, int> > P, Q;
pair <long long, int> f[N];
pair <long long, int> calc(long long C) {
for (int i = 0; i < P.size(); ++i) {
f[i] = {1LL * (P[i].second - P[0].first + 1) * (P[i].second - P[0].first + 1) + C, 1};
pair <long long, int> cur = get(2 * (P[i].second + 1));
cur.first += 1LL * ((P[i].second + 1) * (P[i].second + 1)) + C;
++cur.second;
f[i] = min(f[i], cur);
if (i + 1 < P.size()) {
long long delta = 0;
if (P[i + 1].first <= P[i].second) {
delta = 1LL * (P[i].second - P[i + 1].first + 1) * (P[i].second - P[i + 1].first + 1);
}
add({- P[i + 1].first, (P[i + 1].first * P[i + 1].first) - delta + f[i].first, f[i].second});
}
}
return {f[P.size() - 1].first - C * f[P.size() - 1].second, f[P.size() - 1].second};
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
for (int i = 0; i < n; ++i) {
if (r[i] > c[i]) swap(r[i], c[i]);
P.push_back({r[i], - c[i]});
}
sort(P.begin(), P.end());
for (auto &[x, y]: P) y = - y;
for (auto [x, y]: P) {
if (Q.size() && y <= Q.back().second) continue;
Q.push_back({x, y});
}
swap(P, Q);
long long L = 0, R = 1e12;
while (L < R) {
int mid = L + R + 1 >> 1;
if (calc(mid).second < mid) R = mid - 1;
else L = mid;
}
return calc(L).first;
}
//
//int main() {
// int n, m, k;
// assert(3 == scanf("%d %d %d", &n, &m, &k));
// std::vector<int> r(n), c(n);
// for (int i = 0; i < n; i++) {
// assert(2 == scanf("%d %d", &r[i], &c[i]));
// }
// long long ans = take_photos(n, m, k, r, c);
//
//
// printf("%lld\n", ans);
// return 0;
//}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'std::pair<long long int, int> get(int)':
aliens.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | while (pointer < convex.size() - 1 && convex[pointer](x) > convex[pointer + 1](x)) ++pointer;
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~
aliens.cpp: In function 'std::pair<long long int, int> calc(long long int)':
aliens.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int i = 0; i < P.size(); ++i) {
| ~~^~~~~~~~~~
aliens.cpp:51:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | if (i + 1 < P.size()) {
| ~~~~~~^~~~~~~~~~
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:68:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
68 | for (auto &[x, y]: P) y = - y;
| ^
aliens.cpp:69:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
69 | for (auto [x, y]: P) {
| ^
aliens.cpp:76:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
76 | int mid = L + R + 1 >> 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... |