#include "job.h"
#include <bits/stdc++.h>
using namespace std;
struct DATA{
int timetaken,value,i;
DATA(int u,int d,int ind){
value=u,timetaken=d,i=ind;
}
DATA(){
timetaken=1e9;
value=1;
}
friend bool operator<(const DATA &a,const DATA&b){
return a.timetaken*b.value<
b.timetaken*a.value;
}
};
priority_queue<DATA>pq;
vector<int>ord;
int deg[1<<18];
long long scheduling_cost(std::vector<int> p, std::vector<int> u, std::vector<int> d) {
int N=p.size();
for(int i=1;i<N;i++)
deg[p[i]]++;
for(int i=0;i<N;i++) if(!deg[i])
pq.push(DATA(u[i],d[i],i));
while(pq.size()){
int K=pq.top().i;
pq.pop();
if(!--deg[p[K]])
pq.push(DATA(u[p[K]],d[p[K]],p[K]));
ord.push_back(K);
}
reverse(ord.begin(),ord.end());
long long curtime=0,ans=0;
for(auto i:ord)
ans+=u[i]*(curtime+=d[i]);
ord.clear();
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
12 ms |
2844 KB |
Output is correct |
6 |
Correct |
20 ms |
5336 KB |
Output is correct |
7 |
Correct |
30 ms |
7884 KB |
Output is correct |
8 |
Correct |
39 ms |
9896 KB |
Output is correct |
9 |
Correct |
40 ms |
9656 KB |
Output is correct |
10 |
Correct |
40 ms |
9676 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
39 ms |
9848 KB |
Output is correct |
13 |
Correct |
41 ms |
9724 KB |
Output is correct |
14 |
Correct |
41 ms |
9672 KB |
Output is correct |
15 |
Correct |
44 ms |
9676 KB |
Output is correct |
16 |
Correct |
40 ms |
9668 KB |
Output is correct |
17 |
Correct |
40 ms |
9816 KB |
Output is correct |
18 |
Correct |
49 ms |
9676 KB |
Output is correct |
19 |
Correct |
41 ms |
9804 KB |
Output is correct |
20 |
Correct |
43 ms |
9840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
64 ms |
11072 KB |
Output is correct |
5 |
Correct |
69 ms |
10692 KB |
Output is correct |
6 |
Correct |
67 ms |
10988 KB |
Output is correct |
7 |
Correct |
66 ms |
10692 KB |
Output is correct |
8 |
Correct |
69 ms |
10788 KB |
Output is correct |
9 |
Correct |
64 ms |
11212 KB |
Output is correct |
10 |
Correct |
68 ms |
10644 KB |
Output is correct |
11 |
Correct |
69 ms |
10732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
860 KB |
Output is correct |
6 |
Correct |
71 ms |
11680 KB |
Output is correct |
7 |
Correct |
67 ms |
11720 KB |
Output is correct |
8 |
Correct |
66 ms |
11208 KB |
Output is correct |
9 |
Correct |
68 ms |
11212 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
3 ms |
1056 KB |
Output is correct |
14 |
Correct |
69 ms |
11276 KB |
Output is correct |
15 |
Correct |
69 ms |
11200 KB |
Output is correct |
16 |
Correct |
73 ms |
11204 KB |
Output is correct |
17 |
Correct |
70 ms |
11464 KB |
Output is correct |
18 |
Correct |
67 ms |
11288 KB |
Output is correct |
19 |
Correct |
71 ms |
11208 KB |
Output is correct |
20 |
Correct |
68 ms |
11204 KB |
Output is correct |
21 |
Correct |
68 ms |
11840 KB |
Output is correct |
22 |
Correct |
68 ms |
11972 KB |
Output is correct |
23 |
Correct |
68 ms |
11200 KB |
Output is correct |
24 |
Correct |
69 ms |
11204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
12 ms |
2844 KB |
Output is correct |
6 |
Correct |
20 ms |
5336 KB |
Output is correct |
7 |
Correct |
30 ms |
7884 KB |
Output is correct |
8 |
Correct |
39 ms |
9896 KB |
Output is correct |
9 |
Correct |
40 ms |
9656 KB |
Output is correct |
10 |
Correct |
40 ms |
9676 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
39 ms |
9848 KB |
Output is correct |
13 |
Correct |
41 ms |
9724 KB |
Output is correct |
14 |
Correct |
41 ms |
9672 KB |
Output is correct |
15 |
Correct |
44 ms |
9676 KB |
Output is correct |
16 |
Correct |
40 ms |
9668 KB |
Output is correct |
17 |
Correct |
40 ms |
9816 KB |
Output is correct |
18 |
Correct |
49 ms |
9676 KB |
Output is correct |
19 |
Correct |
41 ms |
9804 KB |
Output is correct |
20 |
Correct |
43 ms |
9840 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
64 ms |
11072 KB |
Output is correct |
25 |
Correct |
69 ms |
10692 KB |
Output is correct |
26 |
Correct |
67 ms |
10988 KB |
Output is correct |
27 |
Correct |
66 ms |
10692 KB |
Output is correct |
28 |
Correct |
69 ms |
10788 KB |
Output is correct |
29 |
Correct |
64 ms |
11212 KB |
Output is correct |
30 |
Correct |
68 ms |
10644 KB |
Output is correct |
31 |
Correct |
69 ms |
10732 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
444 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
3 ms |
860 KB |
Output is correct |
37 |
Correct |
71 ms |
11680 KB |
Output is correct |
38 |
Correct |
67 ms |
11720 KB |
Output is correct |
39 |
Correct |
66 ms |
11208 KB |
Output is correct |
40 |
Correct |
68 ms |
11212 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
1056 KB |
Output is correct |
45 |
Correct |
69 ms |
11276 KB |
Output is correct |
46 |
Correct |
69 ms |
11200 KB |
Output is correct |
47 |
Correct |
73 ms |
11204 KB |
Output is correct |
48 |
Correct |
70 ms |
11464 KB |
Output is correct |
49 |
Correct |
67 ms |
11288 KB |
Output is correct |
50 |
Correct |
71 ms |
11208 KB |
Output is correct |
51 |
Correct |
68 ms |
11204 KB |
Output is correct |
52 |
Correct |
68 ms |
11840 KB |
Output is correct |
53 |
Correct |
68 ms |
11972 KB |
Output is correct |
54 |
Correct |
68 ms |
11200 KB |
Output is correct |
55 |
Correct |
69 ms |
11204 KB |
Output is correct |
56 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
57 |
Halted |
0 ms |
0 KB |
- |