QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#732130#3998. The Profiteerlwm7708WA 486ms6368kbC++173.2kb2024-11-10 13:22:482024-11-10 13:22:48

Judging History

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

  • [2024-11-10 13:22:48]
  • 评测
  • 测评结果:WA
  • 用时:486ms
  • 内存:6368kb
  • [2024-11-10 13:22:48]
  • 提交

answer

#include <algorithm>
#include <cstdint>
#include <ios>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>

template <typename F>
class y_combinator {

private:

    F f;

public:

    explicit y_combinator(F&& f) : f(f) {}

    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const {

        return f(*this, std::forward<Args>(args)...);

    }

};

template <typename F>
y_combinator(F) -> y_combinator<F>;

void solve() {

    using dp_t = std::vector<std::int64_t>;

    std::int64_t e;
    std::int32_t k;
    std::int32_t n;

    std::cin >> n >> k >> e;

    std::vector<std::int32_t> a(n);
    std::vector<std::int32_t> b(n);
    std::vector<std::int32_t> v(n);

    for (std::int32_t i = 0; i < n; ++i) {
        std::cin >> v[i] >> a[i] >> b[i];
    }

    std::vector<std::int32_t> rs(n);

    y_combinator(
        [&](
            auto self, std::int32_t idx_l, std::int32_t idx_r, std::int32_t lo, std::int32_t hi,
            dp_t dp
        ) -> void {
            if (hi - lo <= 1) {
                for (std::int32_t i = idx_l; i < idx_r; ++i) {
                    rs[i] = hi;
                }
                return;
            }
            const auto apply = [&](
                dp_t dp, std::int32_t idx_l, std::int32_t idx_r, bool tp
            ) -> dp_t {
                for (std::int32_t i = idx_l; i < idx_r; ++i) {
                    const std::int32_t cst = (!tp ? a : b)[i];
                    for (std::int32_t j = k; j >= cst; --j) {
                        dp[j] = std::max(dp[j], dp[j - cst] + v[i]);
                    }
                }
                return dp;
            };
            std::int32_t c_hi = hi;
            const std::int32_t idx_m = (idx_l + idx_r) / 2;
            std::int32_t c_lo = std::max(lo, idx_m - 1);
            dp_t c_dp = apply(dp, lo + 1, c_lo + 1, false);
            while (c_hi - c_lo > 1) {
                const std::int32_t mi = (c_lo + c_hi) / 2;
                const dp_t n_dp = apply(apply(c_dp, c_lo + 1, mi + 1, true), mi + 1, c_hi, false);
                if (std::accumulate(std::begin(n_dp), std::end(n_dp), std::int64_t()) <= e * k) {
                    c_dp = apply(c_dp, mi, c_hi, false);
                    c_hi = mi;
                } else {
                    c_dp = apply(c_dp, c_lo + 1, mi + 1, true);
                    c_lo = mi;
                }
            }
            rs[idx_m] = c_hi;
            if (idx_l < idx_m) {
                self(idx_l, idx_m, lo, rs[idx_m], apply(dp, rs[idx_m], hi, false));
            }
            if (idx_r > idx_m + 1) {
                self(
                    idx_m + 1, idx_r, rs[idx_m] - 1, hi,
                    apply(apply(dp, lo + 1, idx_m + 1, false), idx_m + 1, rs[idx_m], true)
                );
            }
        }
    )(0, n, -1, n, dp_t(k + 1));

    std::cout << std::int64_t(n) * n - std::accumulate(
        std::begin(rs), std::end(rs), std::int64_t()
    ) << '\n';

}

int main() {

    std::cin.tie(nullptr);

    std::ios_base::sync_with_stdio(false);

    solve();

    return 0;

}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3652kb

input:

4 5 3
3 2 4
1 2 3
2 1 2
3 1 3

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

4 5 4
3 2 4
1 2 3
2 1 2
3 1 3

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

4 5 5
3 2 4
1 2 3
2 1 2
3 1 3

output:

7

result:

ok single line: '7'

Test #4:

score: 0
Accepted
time: 304ms
memory: 6368kb

input:

200000 50 23333
2620 5 21
8192 17 34
6713 38 46
6687 13 42
390 9 13
4192 7 37
7898 17 21
1471 16 45
3579 22 40
9628 8 23
7164 28 45
3669 14 31
5549 29 35
4670 30 39
5811 15 20
4162 18 29
7590 29 41
7786 23 35
383 9 40
5576 39 46
5586 4 9
1110 14 33
8568 4 6
8548 39 42
9133 10 42
6679 22 39
8353 33 3...

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Wrong Answer
time: 486ms
memory: 6236kb

input:

200000 50 233332
8019 18 20
3111 27 40
2015 16 47
6491 17 18
1224 30 38
428 23 34
7521 4 41
7252 6 33
4121 32 45
4230 18 35
1605 21 42
9489 17 25
3704 35 45
6202 8 22
6493 1 5
3041 14 46
4509 23 43
9646 11 48
5294 19 27
3562 19 40
9408 30 47
1751 21 29
4053 4 27
5596 32 49
8609 13 29
1686 4 31
3588 ...

output:

26817270

result:

wrong answer 1st lines differ - expected: '17523021', found: '26817270'