QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#458142 | #8831. Chemistry Class | ucup-team3678# | WA | 53ms | 10948kb | C++14 | 2.0kb | 2024-06-29 16:00:14 | 2024-06-29 16:00:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
long long a[N], f[N];
long long mx[1 << 20];
void build(int k, int l, int r) {
mx[k] = 1e18;
if (l == r) {
return;
}
int mid = (l + r) >> 1;
build(k << 1, l, mid);
build(k << 1 | 1, mid + 1, r);
}
void modify(int k, int l, int r, int x, long long y) {
mx[k] = min(mx[k], y);
if (l == r) return;
int mid = (l + r) >> 1;
if (x <= mid) modify(k << 1, l, mid, x, y);
else modify(k << 1 | 1, mid + 1, r, x, y);
}
long long query(int k, int l, int r, int x, int y) {
if (l > y || r < x) return 1e18;
if (l >= x && r <= y) return mx[k];
int mid = (l + r) >> 1;
return min(query(k << 1, l, mid, x, y), query(k << 1 | 1, mid + 1, r, x, y));
}
signed main() {
int T; scanf("%d", &T);
while (T--) {
int n; scanf("%d", &n);
long long A, B; scanf("%lld%lld", &A, &B);
for (int i = 1; i <= 2 * n; ++i) {
scanf("%lld", &a[i]), f[i] = 1e18;
}
sort(a + 1, a + n + 1);
a[0] = 0;
for (int i = 2; i <= n + n; i += 2) {
if (a[i] - a[i - 1] > A) {
a[0] = 1;
}
}
if (a[0]) {
puts("-1");
continue;
}
build(1, 0, n + n), modify(1, 0, n + n, 0, 0ll);
for (int i = 2, j = 1, k = 1; i <= 2 * n; i += 2) {
while (a[i] - a[j] > A) j += 2;
while (k <= i && a[i] - a[k] > B) k += 2;
f[i] = f[i - 2] + (a[i] - a[i - 1] > B);
if (j + 1 != i) {
if (a[i - 1] - a[i - 2] > B) {
j = k = i - 1;
} else {
f[i] = min(f[i], query(1, 0, n + n, j - 1, n + n) + 1);
f[i] = min(f[i], query(1, 0, n + n, k - 1, n + n));
}
}
modify(1, 0, n + n, i, f[i]);
}
printf("%lld\n", n - f[n + n]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7836kb
input:
4 1 2 1 42 69 2 3 1 1 2 3 4 2 5 1 6 1 3 4 5 19 1 1 7 8 9 10 11 12 13 14 20
output:
-1 2 1 4
result:
ok 4 number(s): "-1 2 1 4"
Test #2:
score: -100
Wrong Answer
time: 53ms
memory: 10948kb
input:
1 199996 67013419502794 1 403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...
output:
-1
result:
wrong answer 1st numbers differ - expected: '0', found: '-1'