/**
* 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;
struct node_t {
int node, u;
};
inline bool operator<(const node_t& n1, const node_t& n2) {
return n1.u < n2.u || (n1.u == n2.u && 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> pq;
pq.emplace(node_t{0, u[0]});
while (!pq.empty()) {
int t = pq.top().node;
pq.pop();
time += d[t], cost += time * u[t];
for (int neighb : graph[t])
pq.emplace(node_t{neighb, u[neighb]});
}
return cost;
}
# |
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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
19 ms |
4904 KB |
Output is correct |
6 |
Correct |
33 ms |
9548 KB |
Output is correct |
7 |
Correct |
49 ms |
14368 KB |
Output is correct |
8 |
Correct |
85 ms |
19104 KB |
Output is correct |
9 |
Correct |
69 ms |
19104 KB |
Output is correct |
10 |
Correct |
73 ms |
19128 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
75 ms |
19020 KB |
Output is correct |
13 |
Correct |
72 ms |
19120 KB |
Output is correct |
14 |
Correct |
101 ms |
19248 KB |
Output is correct |
15 |
Correct |
72 ms |
19124 KB |
Output is correct |
16 |
Correct |
68 ms |
19084 KB |
Output is correct |
17 |
Correct |
68 ms |
19120 KB |
Output is correct |
18 |
Correct |
91 ms |
19132 KB |
Output is correct |
19 |
Correct |
72 ms |
19124 KB |
Output is correct |
20 |
Correct |
71 ms |
19080 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 |
91 ms |
14368 KB |
Output is correct |
5 |
Correct |
104 ms |
14364 KB |
Output is correct |
6 |
Correct |
117 ms |
14380 KB |
Output is correct |
7 |
Correct |
85 ms |
14380 KB |
Output is correct |
8 |
Correct |
90 ms |
14384 KB |
Output is correct |
9 |
Correct |
103 ms |
14360 KB |
Output is correct |
10 |
Correct |
111 ms |
14396 KB |
Output is correct |
11 |
Correct |
91 ms |
14364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
19 ms |
4904 KB |
Output is correct |
6 |
Correct |
33 ms |
9548 KB |
Output is correct |
7 |
Correct |
49 ms |
14368 KB |
Output is correct |
8 |
Correct |
85 ms |
19104 KB |
Output is correct |
9 |
Correct |
69 ms |
19104 KB |
Output is correct |
10 |
Correct |
73 ms |
19128 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
75 ms |
19020 KB |
Output is correct |
13 |
Correct |
72 ms |
19120 KB |
Output is correct |
14 |
Correct |
101 ms |
19248 KB |
Output is correct |
15 |
Correct |
72 ms |
19124 KB |
Output is correct |
16 |
Correct |
68 ms |
19084 KB |
Output is correct |
17 |
Correct |
68 ms |
19120 KB |
Output is correct |
18 |
Correct |
91 ms |
19132 KB |
Output is correct |
19 |
Correct |
72 ms |
19124 KB |
Output is correct |
20 |
Correct |
71 ms |
19080 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
91 ms |
14368 KB |
Output is correct |
25 |
Correct |
104 ms |
14364 KB |
Output is correct |
26 |
Correct |
117 ms |
14380 KB |
Output is correct |
27 |
Correct |
85 ms |
14380 KB |
Output is correct |
28 |
Correct |
90 ms |
14384 KB |
Output is correct |
29 |
Correct |
103 ms |
14360 KB |
Output is correct |
30 |
Correct |
111 ms |
14396 KB |
Output is correct |
31 |
Correct |
91 ms |
14364 KB |
Output is correct |
32 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |