/**
* What an interesting pratice contest problem!
*
* Time Complexity: O(n * log(n) + m) (m is the num of edges)
* Implementation 1
*/
#include <bits/stdc++.h>
#include "job.h"
typedef long long ll;
typedef std::vector<int> vec;
const ll INF = 0x3f3f3f3f3f3f;
struct node_t {
int node;
double weight;
};
inline bool operator>(const node_t& n1, const node_t& n2) {
return n1.weight > n2.weight || (n1.weight == n2.weight && n1.node > n2.node);
}
ll scheduling_cost(std::vector<int> p, std::vector<int> u, std::vector<int> d) {
int n = p.size();
std::vector<vec> graph(n, vec()); // a reversed graph
for (int i = 1; i < n; i++)
graph[p[i]].emplace_back(i);
ll time = 0, cost = 0;
std::priority_queue<node_t, std::vector<node_t>, std::greater<node_t>> pq;
pq.emplace(node_t{0, -INF});
while (!pq.empty()) {
int t = pq.top().node;
pq.pop();
time += d[t], cost += time * u[t];
for (int neighb : graph[t]) {
double weight = INF;
if (u[neighb] > 0)
weight = double(d[neighb]) / u[neighb];
pq.emplace(node_t{neighb, weight});
}
}
return cost;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
17 ms |
4156 KB |
Output is correct |
6 |
Correct |
33 ms |
8120 KB |
Output is correct |
7 |
Correct |
50 ms |
12020 KB |
Output is correct |
8 |
Correct |
70 ms |
15828 KB |
Output is correct |
9 |
Correct |
66 ms |
15940 KB |
Output is correct |
10 |
Correct |
71 ms |
16024 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
72 ms |
15948 KB |
Output is correct |
13 |
Correct |
70 ms |
15932 KB |
Output is correct |
14 |
Correct |
67 ms |
15996 KB |
Output is correct |
15 |
Correct |
74 ms |
15936 KB |
Output is correct |
16 |
Correct |
71 ms |
15940 KB |
Output is correct |
17 |
Correct |
66 ms |
15952 KB |
Output is correct |
18 |
Correct |
66 ms |
15888 KB |
Output is correct |
19 |
Correct |
79 ms |
15940 KB |
Output is correct |
20 |
Correct |
74 ms |
15960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
97 ms |
14628 KB |
Output is correct |
5 |
Correct |
111 ms |
14676 KB |
Output is correct |
6 |
Correct |
113 ms |
14632 KB |
Output is correct |
7 |
Correct |
99 ms |
14656 KB |
Output is correct |
8 |
Correct |
101 ms |
14648 KB |
Output is correct |
9 |
Correct |
100 ms |
14644 KB |
Output is correct |
10 |
Correct |
98 ms |
14648 KB |
Output is correct |
11 |
Correct |
107 ms |
14724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
5 ms |
1236 KB |
Output is correct |
6 |
Correct |
96 ms |
16932 KB |
Output is correct |
7 |
Correct |
94 ms |
16956 KB |
Output is correct |
8 |
Correct |
95 ms |
16916 KB |
Output is correct |
9 |
Correct |
95 ms |
16960 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
4 ms |
1204 KB |
Output is correct |
13 |
Correct |
5 ms |
1292 KB |
Output is correct |
14 |
Correct |
95 ms |
16920 KB |
Output is correct |
15 |
Correct |
97 ms |
16916 KB |
Output is correct |
16 |
Correct |
107 ms |
17032 KB |
Output is correct |
17 |
Correct |
100 ms |
17012 KB |
Output is correct |
18 |
Correct |
97 ms |
17080 KB |
Output is correct |
19 |
Correct |
98 ms |
17076 KB |
Output is correct |
20 |
Correct |
93 ms |
16936 KB |
Output is correct |
21 |
Correct |
127 ms |
17068 KB |
Output is correct |
22 |
Correct |
112 ms |
16932 KB |
Output is correct |
23 |
Correct |
98 ms |
16956 KB |
Output is correct |
24 |
Correct |
93 ms |
16960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
69 ms |
19124 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
17 ms |
4156 KB |
Output is correct |
6 |
Correct |
33 ms |
8120 KB |
Output is correct |
7 |
Correct |
50 ms |
12020 KB |
Output is correct |
8 |
Correct |
70 ms |
15828 KB |
Output is correct |
9 |
Correct |
66 ms |
15940 KB |
Output is correct |
10 |
Correct |
71 ms |
16024 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
72 ms |
15948 KB |
Output is correct |
13 |
Correct |
70 ms |
15932 KB |
Output is correct |
14 |
Correct |
67 ms |
15996 KB |
Output is correct |
15 |
Correct |
74 ms |
15936 KB |
Output is correct |
16 |
Correct |
71 ms |
15940 KB |
Output is correct |
17 |
Correct |
66 ms |
15952 KB |
Output is correct |
18 |
Correct |
66 ms |
15888 KB |
Output is correct |
19 |
Correct |
79 ms |
15940 KB |
Output is correct |
20 |
Correct |
74 ms |
15960 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
97 ms |
14628 KB |
Output is correct |
25 |
Correct |
111 ms |
14676 KB |
Output is correct |
26 |
Correct |
113 ms |
14632 KB |
Output is correct |
27 |
Correct |
99 ms |
14656 KB |
Output is correct |
28 |
Correct |
101 ms |
14648 KB |
Output is correct |
29 |
Correct |
100 ms |
14644 KB |
Output is correct |
30 |
Correct |
98 ms |
14648 KB |
Output is correct |
31 |
Correct |
107 ms |
14724 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
1236 KB |
Output is correct |
37 |
Correct |
96 ms |
16932 KB |
Output is correct |
38 |
Correct |
94 ms |
16956 KB |
Output is correct |
39 |
Correct |
95 ms |
16916 KB |
Output is correct |
40 |
Correct |
95 ms |
16960 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
324 KB |
Output is correct |
43 |
Correct |
4 ms |
1204 KB |
Output is correct |
44 |
Correct |
5 ms |
1292 KB |
Output is correct |
45 |
Correct |
95 ms |
16920 KB |
Output is correct |
46 |
Correct |
97 ms |
16916 KB |
Output is correct |
47 |
Correct |
107 ms |
17032 KB |
Output is correct |
48 |
Correct |
100 ms |
17012 KB |
Output is correct |
49 |
Correct |
97 ms |
17080 KB |
Output is correct |
50 |
Correct |
98 ms |
17076 KB |
Output is correct |
51 |
Correct |
93 ms |
16936 KB |
Output is correct |
52 |
Correct |
127 ms |
17068 KB |
Output is correct |
53 |
Correct |
112 ms |
16932 KB |
Output is correct |
54 |
Correct |
98 ms |
16956 KB |
Output is correct |
55 |
Correct |
93 ms |
16960 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Incorrect |
69 ms |
19124 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |