Submission #211376

# Submission time Handle Problem Language Result Execution time Memory
211376 2020-03-20T08:33:33 Z 2qbingxuan Job Scheduling (IOI19_job) C++14
100 / 100
264 ms 20200 KB
//#include "job.h"
#include <bits/stdc++.h>
using namespace std;

long long scheduling_cost(std::vector<int> P, std::vector<int> U, std::vector<int> D) {
    vector<int64_t> p(P.begin(),P.end());
    vector<int64_t> u(U.begin(),U.end());
    vector<int64_t> d(D.begin(),D.end());
    int n = p.size();
    struct node {
        long long u, d;
        int id;
        bool operator<(node p)const{
            return u*p.d < d*p.u;
        }
    };
    long long ans = 0;
    vector<int> pa(n);
    iota(pa.begin(), pa.end(), 0);
    function<int(int)> anc = [&](int x){
        return x==pa[x] ? x : pa[x]=anc(pa[x]);
    };
    auto add = [&](int a, int i) {
        //cerr << a << ' ' << i << '\n';
        ans -= 1LL * d[i] * u[a];
        //cerr << "ans="<<ans << '\n';
        d[a] += d[i];
        u[a] += u[i];
    };
    priority_queue<node> pq;
    for(int i = 0; i < n; i++)
        pq.push({u[i],d[i],i});
    while(pq.size()) {
        node x;
        do x=pq.top(), pq.pop(); while(pq.size() && (x.u!=u[x.id] || x.d!=d[x.id]));
        int i = x.id;
        if(p[i] == -1 || pa[i] != i) continue;
        //cerr << "u,d = " << x.u << ' ' << x.d << '\n';
        //cerr << "i = " << i << '\n';
        int a = anc(p[i]);
        pa[i] = a;
        add(a, i);
        //cout << "a: " << a << ' ' << u[a] << ' ' << d[a] << '\n';
        pq.push({u[a],d[a],a});
    }
    //cerr << "ans = " << ans << '\n';
    //cerr << u[0] << ' ' << d[0] << '\n';
    ans += 1LL * u[0] * d[0];
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 55 ms 5360 KB Output is correct
6 Correct 105 ms 10220 KB Output is correct
7 Correct 176 ms 16620 KB Output is correct
8 Correct 259 ms 19944 KB Output is correct
9 Correct 249 ms 19944 KB Output is correct
10 Correct 264 ms 20072 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 250 ms 19944 KB Output is correct
13 Correct 196 ms 19944 KB Output is correct
14 Correct 220 ms 19944 KB Output is correct
15 Correct 174 ms 19944 KB Output is correct
16 Correct 200 ms 19944 KB Output is correct
17 Correct 255 ms 19948 KB Output is correct
18 Correct 250 ms 19944 KB Output is correct
19 Correct 167 ms 19944 KB Output is correct
20 Correct 172 ms 19944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 195 ms 16876 KB Output is correct
5 Correct 199 ms 16744 KB Output is correct
6 Correct 207 ms 16892 KB Output is correct
7 Correct 195 ms 16872 KB Output is correct
8 Correct 195 ms 16872 KB Output is correct
9 Correct 209 ms 16756 KB Output is correct
10 Correct 196 ms 16872 KB Output is correct
11 Correct 195 ms 16744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 12 ms 1476 KB Output is correct
6 Correct 202 ms 19048 KB Output is correct
7 Correct 202 ms 19176 KB Output is correct
8 Correct 207 ms 19052 KB Output is correct
9 Correct 200 ms 19176 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 11 ms 1348 KB Output is correct
13 Correct 12 ms 1476 KB Output is correct
14 Correct 210 ms 19048 KB Output is correct
15 Correct 204 ms 19048 KB Output is correct
16 Correct 199 ms 19048 KB Output is correct
17 Correct 213 ms 19180 KB Output is correct
18 Correct 201 ms 19052 KB Output is correct
19 Correct 208 ms 19048 KB Output is correct
20 Correct 201 ms 19048 KB Output is correct
21 Correct 201 ms 19048 KB Output is correct
22 Correct 199 ms 19048 KB Output is correct
23 Correct 214 ms 19048 KB Output is correct
24 Correct 199 ms 19176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 254 ms 16872 KB Output is correct
3 Correct 255 ms 20200 KB Output is correct
4 Correct 252 ms 19944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 55 ms 5360 KB Output is correct
6 Correct 105 ms 10220 KB Output is correct
7 Correct 176 ms 16620 KB Output is correct
8 Correct 259 ms 19944 KB Output is correct
9 Correct 249 ms 19944 KB Output is correct
10 Correct 264 ms 20072 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 250 ms 19944 KB Output is correct
13 Correct 196 ms 19944 KB Output is correct
14 Correct 220 ms 19944 KB Output is correct
15 Correct 174 ms 19944 KB Output is correct
16 Correct 200 ms 19944 KB Output is correct
17 Correct 255 ms 19948 KB Output is correct
18 Correct 250 ms 19944 KB Output is correct
19 Correct 167 ms 19944 KB Output is correct
20 Correct 172 ms 19944 KB Output is correct
21 Correct 4 ms 256 KB Output is correct
22 Correct 4 ms 256 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 195 ms 16876 KB Output is correct
25 Correct 199 ms 16744 KB Output is correct
26 Correct 207 ms 16892 KB Output is correct
27 Correct 195 ms 16872 KB Output is correct
28 Correct 195 ms 16872 KB Output is correct
29 Correct 209 ms 16756 KB Output is correct
30 Correct 196 ms 16872 KB Output is correct
31 Correct 195 ms 16744 KB Output is correct
32 Correct 4 ms 256 KB Output is correct
33 Correct 4 ms 256 KB Output is correct
34 Correct 5 ms 256 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 12 ms 1476 KB Output is correct
37 Correct 202 ms 19048 KB Output is correct
38 Correct 202 ms 19176 KB Output is correct
39 Correct 207 ms 19052 KB Output is correct
40 Correct 200 ms 19176 KB Output is correct
41 Correct 4 ms 256 KB Output is correct
42 Correct 5 ms 512 KB Output is correct
43 Correct 11 ms 1348 KB Output is correct
44 Correct 12 ms 1476 KB Output is correct
45 Correct 210 ms 19048 KB Output is correct
46 Correct 204 ms 19048 KB Output is correct
47 Correct 199 ms 19048 KB Output is correct
48 Correct 213 ms 19180 KB Output is correct
49 Correct 201 ms 19052 KB Output is correct
50 Correct 208 ms 19048 KB Output is correct
51 Correct 201 ms 19048 KB Output is correct
52 Correct 201 ms 19048 KB Output is correct
53 Correct 199 ms 19048 KB Output is correct
54 Correct 214 ms 19048 KB Output is correct
55 Correct 199 ms 19176 KB Output is correct
56 Correct 4 ms 256 KB Output is correct
57 Correct 254 ms 16872 KB Output is correct
58 Correct 255 ms 20200 KB Output is correct
59 Correct 252 ms 19944 KB Output is correct
60 Correct 4 ms 256 KB Output is correct
61 Correct 4 ms 256 KB Output is correct
62 Correct 4 ms 384 KB Output is correct
63 Correct 5 ms 384 KB Output is correct
64 Correct 5 ms 384 KB Output is correct
65 Correct 5 ms 384 KB Output is correct
66 Correct 4 ms 256 KB Output is correct
67 Correct 5 ms 256 KB Output is correct
68 Correct 4 ms 384 KB Output is correct
69 Correct 5 ms 384 KB Output is correct
70 Correct 4 ms 384 KB Output is correct
71 Correct 5 ms 384 KB Output is correct
72 Correct 5 ms 384 KB Output is correct
73 Correct 5 ms 384 KB Output is correct
74 Correct 5 ms 384 KB Output is correct
75 Correct 5 ms 384 KB Output is correct
76 Correct 5 ms 384 KB Output is correct
77 Correct 5 ms 256 KB Output is correct
78 Correct 4 ms 256 KB Output is correct
79 Correct 4 ms 384 KB Output is correct
80 Correct 4 ms 256 KB Output is correct
81 Correct 4 ms 256 KB Output is correct
82 Correct 5 ms 256 KB Output is correct
83 Correct 4 ms 256 KB Output is correct
84 Correct 4 ms 256 KB Output is correct
85 Correct 4 ms 256 KB Output is correct
86 Correct 4 ms 256 KB Output is correct
87 Correct 4 ms 256 KB Output is correct
88 Correct 8 ms 1024 KB Output is correct
89 Correct 11 ms 1220 KB Output is correct
90 Correct 13 ms 1476 KB Output is correct
91 Correct 51 ms 5368 KB Output is correct
92 Correct 104 ms 10220 KB Output is correct
93 Correct 259 ms 19816 KB Output is correct
94 Correct 244 ms 19816 KB Output is correct
95 Correct 260 ms 19816 KB Output is correct
96 Correct 246 ms 19944 KB Output is correct
97 Correct 241 ms 19816 KB Output is correct
98 Correct 240 ms 19976 KB Output is correct
99 Correct 223 ms 19816 KB Output is correct
100 Correct 243 ms 19816 KB Output is correct
101 Correct 259 ms 20200 KB Output is correct
102 Correct 213 ms 19816 KB Output is correct
103 Correct 247 ms 19816 KB Output is correct
104 Correct 246 ms 19944 KB Output is correct
105 Correct 184 ms 19944 KB Output is correct
106 Correct 204 ms 19304 KB Output is correct