QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#459220 | #8831. Chemistry Class | ucup-team3924# | WA | 68ms | 9484kb | C++20 | 2.0kb | 2024-06-29 23:44:53 | 2024-06-29 23:44:59 |
Judging History
answer
#include<bits/stdc++.h>
struct SlidingWindow {
std::deque<int> pos;
std::vector<int> value;
SlidingWindow(int N): value(1 + N) {}
void push(int i, int v) {
value[i] = v;
while (!pos.empty() && v >= value[pos.back()])
pos.pop_back();
pos.push_back(i);
}
void pop(int i) {
if (!pos.empty() && pos.front() == i)
pos.pop_front();
}
int query() {
if (pos.empty())
return -1000000000;
return value[pos.front()];
}
void dump() {
std::cerr << "dump\n";
std::cerr << " ";
for (auto it: pos)
std::cerr << it << " ";
std::cerr << "\n ";
for (auto it: pos)
std::cerr << value[it] << " ";
std::cerr << "\n";
}
};
void solve_test() {
int n;
long long A, B;
std::cin >> n >> A >> B;
std::vector<long long> v(1 + 2 * n);
for (int i = 1; i <= 2 * n; i++)
std::cin >> v[i];
n = n * 2;
std::sort(v.begin() + 1, v.end());
std::vector<int> dp(1 + n, -1000000000);
dp[0] = 0;
SlidingWindow ds(n);
ds.push(0, 0);
int last_invalid = 1;
for (int i = 1; i <= n; i++) {
if (i % 2 == 0) {
if (v[i] - v[i - 1] <= A) {
dp[i] = std::max(dp[i], dp[i - 2] + (v[i] - v[i - 1] <= B));
}
while (last_invalid + 1 <= i + 1 && (v[i] - v[last_invalid] > A || (i > 2 && v[i - 1] - v[i - 2] > B))) {
ds.pop(last_invalid - 1);
last_invalid += 2;
}
if (last_invalid < i) {
dp[i] = std::max(dp[i], i / 2 + ds.query() - 1);
}
ds.push(i, dp[i] - i / 2);
}
}
if (dp[n] < 0)
std::cout << "-1\n";
else
std::cout << dp[n] << "\n";
}
int main(){
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
int t;
std::cin >> t;
while (t--) solve_test();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 0
Accepted
time: 66ms
memory: 9316kb
input:
1 199996 67013419502794 1 403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 59ms
memory: 9344kb
input:
1 199998 38987266278826 1 974183459404323858 517476981059568123 730207399881008603 532509909948600146 89227878552241675 16653300445469756 791674368913652595 92177901403222015 980536748304824579 581564387828767376 471919726893404451 759601909683722004 632340812998214017 818440789777778368 18845836031...
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 67ms
memory: 9344kb
input:
1 199996 54170919220045 1 968843690955781467 596307347951820347 406785475849275444 383666938223357986 725160735782817082 132577412512120631 891899794864087098 779434145671998619 932681297277907326 208765550447928461 385078857912267975 669360937040314510 917331948890514855 505938744714587815 47145437...
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: -100
Wrong Answer
time: 68ms
memory: 9484kb
input:
1 199998 35667463938291 8255384928693 770468016026697053 519790816750772730 110085058423772871 85144239858008037 782003096084947976 938498644167289660 693768718229582367 242186248813489674 155335549252315364 428982852761422230 890445026369869037 86401573937739054 9122788624365829 63351367715811463 1...
output:
193300
result:
wrong answer 1st numbers differ - expected: '193326', found: '193300'