QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#459016#8831. Chemistry Classucup-team3924#WA 9ms7972kbC++201.9kb2024-06-29 21:20:472024-06-29 21:20:48

Judging History

你现在查看的是最新测评结果

  • [2024-06-29 21:20:48]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:7972kb
  • [2024-06-29 21:20:47]
  • 提交

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: value)
            std::cerr << it << " ";
        std::cerr << "\n";
    }
};

void solve_test() {
    int n;
    long long A, B;

    std::cin >> n >> A >> B;

    std::vector<int> 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 < i && 
                (v[i] - v[last_invalid] > A || (i > 2 && v[i - 1] - v[i - 2] > B))) {

                ds.pop(last_invalid - 1);
                last_invalid += 2;
            }

            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: -100
Wrong Answer
time: 9ms
memory: 7972kb

input:

1
199996 67013419502794 1
403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...

output:

199995

result:

wrong answer 1st numbers differ - expected: '0', found: '199995'