QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#500150#8707. JobsQwerty1232#0 143ms43592kbC++232.5kb2024-07-31 23:22:552024-07-31 23:22:56

Judging History

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

  • [2024-07-31 23:22:56]
  • 评测
  • 测评结果:0
  • 用时:143ms
  • 内存:43592kb
  • [2024-07-31 23:22:55]
  • 提交

answer

#include <bits/stdc++.h>

int32_t main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    int64_t S;
    std::cin >> n >> S;
    std::vector<int> profit(n + 1), dep(n + 1);
    dep[0] = -1;
    for (int i = 1; i <= n; i++) {
        std::cin >> profit[i] >> dep[i];
    }
    n++;
    std::vector<std::vector<int>> gr(n);
    for (int i = 1; i < n; i++) {
        gr[dep[i]].push_back(i);
    }

    using Fuck = std::pair<std::pair<int64_t, int64_t>, std::vector<int>>;
    std::vector<Fuck> fuck(n, {{-1, -1}, {}});
    for (int i = n - 1; i > 0; i--) {
        std::set<std::pair<Fuck, int>> set;
        if (profit[i] >= 0) {
            fuck[i] = {{0, profit[i]}, gr[i]};
        } else {
            for (int v : gr[i]) {
                if (fuck[v].first.first != -1) {
                    set.insert({fuck[v], v});
                }
            }
            int64_t sum = profit[i], min = profit[i];
            while (sum < 0 && set.size()) {
                auto [p1, id] = set.extract(std::prev(set.end())).value();
                auto &[p, vc] = p1;
                auto &[a, b] = p;
                min = std::min(min, sum + a);
                sum += b;
                for (int v : vc) {
                    if (fuck[v].first.first != -1) {
                        set.insert({fuck[v], v});
                    }
                }
            }
            if (sum < 0) {
                continue;
            } else {
                std::vector<int> nxt;
                for (auto &[a, b] : set) {
                    nxt.push_back(b);
                }
                fuck[i] = {{min, sum}, nxt};
                // set.insert({fuck[i], i});
            }
        }
    }

    int64_t sum = S;
    {
        std::set<std::pair<Fuck, int>> set;
        for (int v : gr[0]) {
            if (fuck[v].first.first != -1) {
                set.insert({fuck[v], v});
            }
        }
        while (set.size()) {
            auto [p1, id] = set.extract(std::prev(set.end())).value();
            auto &[p, vc] = p1;
            auto &[a, b] = p;
            if (sum + a < 0) {
                break;
            }
            sum += b;
            for (int v : vc) {
                if (fuck[v].first.first != -1) {
                    set.insert({fuck[v], v});
                }
            }
        }
    }

    std::cout << sum - S << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 11
Accepted
time: 129ms
memory: 41640kb

input:

299955 1000000000000000000
-2 0
10 1
-9 2
14 3
-11 4
17 5
-21 6
22 7
-22 8
23 9
-41 10
-89 10
49 11
99 12
-120 14
-23 8
130 15
24 16
-51 13
55 19
-144 20
-24 18
-30 18
-54 13
64 24
-105 14
145 21
-60 20
-183 25
61 28
-334 30
340 31
111 26
-135 33
-184 33
191 35
-231 17
-505 27
-570 32
-257 25
238 37...

output:

551168

result:

ok single line: '551168'

Test #2:

score: 0
Wrong Answer
time: 143ms
memory: 43592kb

input:

299932 1000000000000000000
-26 0
-38 0
-521 0
-567 0
-569 0
-235 0
-294 0
-134 0
144 8
-177 0
-458 0
-9675 9
296 7
-15 0
34 1
-21349 9
-15643 9
-280 0
-445 15
-13253 13
-7497 15
-12328 15
-3131 15
7498 21
-172566 24
-14287 13
-24726 13
-1 0
-12603 13
-14221 13
-401 0
-4105 13
-2872 15
-1264 9
-5095 ...

output:

781552

result:

wrong answer 1st lines differ - expected: '797403', found: '781552'

Subtask #2:

score: 0
Wrong Answer

Test #14:

score: 14
Accepted
time: 0ms
memory: 3752kb

input:

17 5
-3 0
4 1
-4 2
9 3
-5 4
13 5
-6 6
8 7
-23 8
28 9
-26 10
31 11
-28 12
33 13
-39 14
41 15
-7 16

output:

16

result:

ok single line: '16'

Test #15:

score: 0
Wrong Answer
time: 0ms
memory: 3816kb

input:

17 1
-14 0
21 1
-15 2
16 3
-22 4
29 5
-32 6
34 7
-33 8
35 9
-10 10
-1 0
6 12
-3 13
5 14
-16 15
22 16

output:

0

result:

wrong answer 1st lines differ - expected: '7', found: '0'

Subtask #3:

score: 0
Wrong Answer

Test #42:

score: 0
Wrong Answer
time: 58ms
memory: 42948kb

input:

300000 0
-1677 0
1678 1
-3010 2
3011 3
-8141 4
8142 5
-11233 6
11234 7
-14400 8
14401 9
-17045 10
17046 11
-19521 12
19522 13
-23178 14
23179 15
-26907 16
26908 17
-28884 18
28885 19
-30742 20
30743 21
-35957 22
35958 23
-38436 24
38437 25
-39739 26
39740 27
-42432 28
42433 29
-47866 30
47867 31
-48...

output:

1

result:

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

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%