QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#282474 | #6420. Certain Scientific Railgun | jrjyy | WA | 1ms | 3556kb | C++20 | 2.7kb | 2023-12-12 09:33:48 | 2023-12-12 09:33:49 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int n;
std::cin >> n;
std::vector<int> x(n), y(n);
for (int i = 0; i < n; ++i) {
std::cin >> x[i] >> y[i];
}
x.push_back(0);
y.push_back(0);
++n;
std::vector<int> pos, neg{n - 1};
for (int i = 0; i < n; ++i) {
if (x[i] >= 0) {
pos.push_back(i);
} else {
neg.push_back(i);
}
}
i64 ans = 1e18;
auto work = [&]() {
auto get = [&](const std::vector<int> &id) {
std::vector<int> v;
for (auto i : id) {
v.push_back(std::abs(x[i]));
}
std::sort(v.begin(), v.end());
v.erase(std::unique(v.begin(), v.end()), v.end());
std::vector<int> l(v.size() + 1), r(v.size() + 1);
for (auto i : id) {
int nx = std::lower_bound(v.begin(), v.end(), std::abs(x[i])) - v.begin();
l[nx] = std::min(l[nx], y[i]);
r[nx] = std::max(r[nx], y[i]);
}
for (int i = int(v.size()) - 1; i >= 0; --i) {
l[i] = std::min(l[i], l[i + 1]);
r[i] = std::max(r[i], r[i + 1]);
}
return std::make_tuple(v, l, r);
};
auto [pv, pl, pr] = get(pos);
auto [nv, nl, nr] = get(neg);
for (int s = 0; s < 4; ++s) {
for (int i = 0, j = 0; i < int(pv.size()); ++i) {
while (j < int(nv.size()) &&
((s & 1 && pl[i + 1] > nl[j + 1]) || (s & 2 && pr[i + 1] < nr[j + 1]))) {
++j;
}
if (j == int(nv.size())) {
break;
}
i64 res = i64(pv[i]) + nv[j] + std::max(pr[i + 1], nr[j + 1]) -
std::min(pl[i + 1], nl[j + 1]);
ans = std::min(ans, res);
}
}
};
for (auto a : {-1, 1}) {
for (auto b : {-1, 1}) {
for (int i = 0; i < n; ++i) {
if (x[i] * a > 0) {
x[i] *= 2;
}
if (y[i] * b > 0) {
y[i] *= 2;
}
}
work();
for (int i = 0; i < n; ++i) {
if (x[i] * a > 0) {
x[i] /= 2;
}
if (y[i] * b > 0) {
y[i] /= 2;
}
}
}
}
std::cout << ans << "\n";
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
3 2 0 1 1 0 4 1 1 -3 -3 4 -4 -2 2 4 1 100 3 100 -100 1 3 -100
output:
0 8 4
result:
ok 3 number(s): "0 8 4"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3452kb
input:
120 4 11 11 -22 -22 33 -33 -44 44 4 -11 11 22 -22 -33 -33 44 44 4 -11 -11 22 22 -33 33 44 -44 4 11 -11 -22 22 33 33 -44 -44 4 -11 11 22 -22 33 33 -44 -44 4 11 11 -22 -22 -33 33 44 -44 4 11 -11 -22 22 -33 -33 44 44 4 -11 -11 22 22 33 -33 -44 44 4 1 1 -2 -2 3 -3 -4 4 4 -1 1 2 -2 -3 -3 4 4 4 -1 -1 2 2 ...
output:
99 99 99 99 99 99 99 99 9 9 9 9 9 9 9 9 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 0 0 0 0 0 0 0 0 4 4 4 4 4 4 4 4 4 100 100 4 100 4 4 100 12 12 12 12 12 12 12 12 0 0 0 0 0 0 0 0 11 100 100 11 100 11 11 100 111 111 111 111 111 111 111 111 300 300 300 300 300 300 300 300 5 5 5 5 5 5 5 5 2 100 100 2 100 2 2 100 ...
result:
wrong answer 50th numbers differ - expected: '4', found: '100'