QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#705222 | #8645. Growing Vegetables is Fun 5 | hhoppitree | 0 | 1ms | 4052kb | C++17 | 2.4kb | 2024-11-02 22:34:17 | 2024-11-02 22:34:18 |
answer
#include <bits/stdc++.h>
using namespace std;
vector<int> calc(int n, vector<int> a, vector<int> b, int d) {
vector<int> res(n * 2 + 1), rev = a;
reverse(rev.begin(), rev.end());
auto append = [&](int l, int r) {
l = (l + 2 * n) % (2 * n), r = (r + 2 * n) % (2 * n);
if (l < r) ++res[l], --res[r + 1];
else ++res[l], ++res[0], --res[r + 1];
};
auto joint = [&](int a, int b, int c, int d) {
return max(min(b, d) - max(a, c) + 1, 0);
};
for (int i = 0; i < n * 2; ++i) {
int l = lower_bound(b.begin(), b.end(), a[i] - d) - b.begin() + 1,
r = upper_bound(b.begin(), b.end(), a[i] + d) - b.begin();
if (l > r) continue;
if (i == n) {
if (r == n) append(1, n);
continue;
}
if (i == 0) {
if (l == 1) append(-n + 1, 0);
continue;
}
int L = min({(int)(upper_bound(a.begin(), a.begin() + n, a[i]) - a.begin() - 1), i, n - 1}),
R = max({(int)(a.size() - (upper_bound(rev.begin(), rev.begin() + n, a[i]) - rev.begin())), n + 1, i});
for (int j = (i + n + 1) % (2 * n); (j - 1 + 2 * n) % (2 * n) != i; j = (j + 1) % (2 * n)) {
int ct = joint(0, L, j, min(j + n - 1, n * 2 - 1)) + joint(R, n * 2 - 1, j, min(j + n - 1, n * 2 - 1));
if (j >= n) ct += joint(0, L, 0, j - n - 1) + joint(R, n * 2 - 1, 0, j - n - 1);
if (ct >= l && ct <= r) {
++res[j], --res[j + 1];
}
}
}
partial_sum(res.begin(), res.end(), res.begin());
for (int i = 0; i < n * 2; ++i) {
res[i] = (res[i] == n);
}
res.pop_back();
return res;
}
int check(int n, vector<int> a, vector<int> b, vector<int> c, int d) {
vector<int> f = calc(n, a, b, d), g = calc(n, a, c, d);
for (int i = 0; i < n * 2; ++i) {
if (f[i] && g[(i + n) % (n * 2)]) return 1;
}
return 0;
}
signed main() {
int n; scanf("%d", &n);
vector<int> a(n * 2), b(n), c(n);
for (auto &x : a) scanf("%d", &x);
for (auto &x : b) scanf("%d", &x);
for (auto &x : c) scanf("%d", &x);
sort(b.begin(), b.end()), sort(c.begin(), c.end());
int L = 0, R = 1e9, res;
while (L <= R) {
int mid = (L + R) >> 1;
if (check(n, a, b, c, mid)) res = mid, R = mid - 1;
else L = mid + 1;
}
printf("%d\n", res);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 1ms
memory: 3796kb
input:
5 71039844 102827355 217531548 220229557 237972610 314010999 309303025 282414480 227324750 127910276 355992665 573821998 974848115 193721993 786455947 602158296 281786121 321727541 140763116 455641294
output:
660837116
result:
ok single line: '660837116'
Test #2:
score: 4
Accepted
time: 0ms
memory: 4052kb
input:
4 1705 9199 9245 9297 9785 8486 3596 2031 356 2834 9555 4667 1881 4772 9778 4863
output:
4427
result:
ok single line: '4427'
Test #3:
score: 4
Accepted
time: 1ms
memory: 3772kb
input:
3 1 1 1 1 1 1 6 4 7 4 2 6
output:
6
result:
ok single line: '6'
Test #4:
score: 4
Accepted
time: 0ms
memory: 3796kb
input:
2 2 2 10 6 9 2 9 2
output:
3
result:
ok single line: '3'
Test #5:
score: 0
Wrong Answer
time: 0ms
memory: 3724kb
input:
1 349142605 778700270 168051580 502698453
output:
0
result:
wrong answer 1st lines differ - expected: '276001817', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Time Limit Exceeded
Test #41:
score: 0
Time Limit Exceeded
input:
300000 619 2319 3493 3715 4353 4926 8022 14367 18919 23666 25565 25582 27245 27303 28880 29568 29918 31815 34986 36861 40022 40147 47041 52120 55624 57816 58553 59319 60056 63512 66442 68907 68915 69471 69714 71129 76758 76761 77220 78196 84558 87950 88697 88782 89810 90113 92091 95040 97273 99148 1...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%