#include "job.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN=2e5;
int n, nxt[mxN], ta[mxN];
vector<int> o;
ll u2[mxN], d2[mxN];
struct cmp {
bool operator()(const int &a, const int &b) {
return d2[a]*u2[b]>d2[b]*u2[a];
}
};
priority_queue<int, vector<int>, cmp> c[mxN];
void dfs(int u) {
o.push_back(u);
for(; c[u].size(); c[u].pop())
dfs(c[u].top());
}
ll scheduling_cost(vector<int> p, vector<int> u, vector<int> d) {
n=p.size();
memset(nxt, -1, 4*n);
iota(ta, ta+n, 0);
for(int i=n-1; ~i; --i) {
u2[i]=u[i];
d2[i]=d[i];
while(c[i].size()) {
int u=c[i].top();
if(cmp()(u, i))
break;
c[i].pop();
nxt[ta[i]]=u;
ta[i]=ta[u];
u2[i]+=u2[u];
d2[i]+=d2[u];
if(c[i].size()<c[u].size())
swap(c[i], c[u]);
for(; c[u].size(); c[u].pop())
c[i].push(c[u].top());
}
if(i)
c[p[i]].push(i);
}
dfs(0);
sort(o.begin(), o.end(), cmp());
ll t=0, ans=0;
for(int i=o.size()-1; ~i; --i) {
for(int j=o[i]; ~j; j=nxt[j]) {
t+=d[j];
ans+=t*u[j];
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
3 ms |
6484 KB |
Output is correct |
3 |
Correct |
4 ms |
6468 KB |
Output is correct |
4 |
Correct |
4 ms |
6612 KB |
Output is correct |
5 |
Correct |
18 ms |
10452 KB |
Output is correct |
6 |
Correct |
32 ms |
14400 KB |
Output is correct |
7 |
Correct |
47 ms |
18256 KB |
Output is correct |
8 |
Correct |
61 ms |
22220 KB |
Output is correct |
9 |
Correct |
61 ms |
22204 KB |
Output is correct |
10 |
Correct |
62 ms |
22096 KB |
Output is correct |
11 |
Correct |
3 ms |
6484 KB |
Output is correct |
12 |
Correct |
67 ms |
22216 KB |
Output is correct |
13 |
Correct |
70 ms |
22108 KB |
Output is correct |
14 |
Correct |
61 ms |
22176 KB |
Output is correct |
15 |
Correct |
59 ms |
22100 KB |
Output is correct |
16 |
Correct |
63 ms |
22364 KB |
Output is correct |
17 |
Correct |
66 ms |
22220 KB |
Output is correct |
18 |
Correct |
62 ms |
22108 KB |
Output is correct |
19 |
Correct |
60 ms |
22104 KB |
Output is correct |
20 |
Correct |
80 ms |
29508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
3 ms |
6484 KB |
Output is correct |
3 |
Correct |
3 ms |
6484 KB |
Output is correct |
4 |
Correct |
118 ms |
18232 KB |
Output is correct |
5 |
Correct |
122 ms |
18256 KB |
Output is correct |
6 |
Correct |
147 ms |
18276 KB |
Output is correct |
7 |
Correct |
120 ms |
18168 KB |
Output is correct |
8 |
Correct |
116 ms |
18240 KB |
Output is correct |
9 |
Correct |
128 ms |
18372 KB |
Output is correct |
10 |
Correct |
119 ms |
18256 KB |
Output is correct |
11 |
Correct |
124 ms |
18292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
3 ms |
6484 KB |
Output is correct |
3 |
Correct |
3 ms |
6484 KB |
Output is correct |
4 |
Correct |
3 ms |
6608 KB |
Output is correct |
5 |
Correct |
6 ms |
7124 KB |
Output is correct |
6 |
Correct |
129 ms |
18184 KB |
Output is correct |
7 |
Correct |
124 ms |
18252 KB |
Output is correct |
8 |
Correct |
120 ms |
18244 KB |
Output is correct |
9 |
Correct |
118 ms |
18196 KB |
Output is correct |
10 |
Correct |
3 ms |
6484 KB |
Output is correct |
11 |
Correct |
3 ms |
6612 KB |
Output is correct |
12 |
Correct |
7 ms |
7116 KB |
Output is correct |
13 |
Correct |
7 ms |
7124 KB |
Output is correct |
14 |
Correct |
123 ms |
18248 KB |
Output is correct |
15 |
Correct |
124 ms |
18220 KB |
Output is correct |
16 |
Correct |
120 ms |
18240 KB |
Output is correct |
17 |
Correct |
122 ms |
18364 KB |
Output is correct |
18 |
Correct |
126 ms |
18272 KB |
Output is correct |
19 |
Correct |
167 ms |
18276 KB |
Output is correct |
20 |
Correct |
134 ms |
18240 KB |
Output is correct |
21 |
Correct |
125 ms |
18212 KB |
Output is correct |
22 |
Correct |
118 ms |
18240 KB |
Output is correct |
23 |
Correct |
120 ms |
18212 KB |
Output is correct |
24 |
Correct |
120 ms |
18260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
62 ms |
22184 KB |
Output is correct |
3 |
Correct |
62 ms |
22212 KB |
Output is correct |
4 |
Correct |
61 ms |
22212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6496 KB |
Output is correct |
2 |
Correct |
3 ms |
6484 KB |
Output is correct |
3 |
Correct |
3 ms |
6484 KB |
Output is correct |
4 |
Correct |
3 ms |
6484 KB |
Output is correct |
5 |
Correct |
3 ms |
6484 KB |
Output is correct |
6 |
Correct |
3 ms |
6484 KB |
Output is correct |
7 |
Correct |
3 ms |
6484 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
3 ms |
6484 KB |
Output is correct |
10 |
Correct |
3 ms |
6576 KB |
Output is correct |
11 |
Correct |
3 ms |
6576 KB |
Output is correct |
12 |
Correct |
3 ms |
6484 KB |
Output is correct |
13 |
Correct |
3 ms |
6484 KB |
Output is correct |
14 |
Correct |
3 ms |
6484 KB |
Output is correct |
15 |
Correct |
4 ms |
6612 KB |
Output is correct |
16 |
Correct |
3 ms |
6484 KB |
Output is correct |
17 |
Correct |
3 ms |
6580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
3 ms |
6484 KB |
Output is correct |
3 |
Correct |
4 ms |
6468 KB |
Output is correct |
4 |
Correct |
4 ms |
6612 KB |
Output is correct |
5 |
Correct |
18 ms |
10452 KB |
Output is correct |
6 |
Correct |
32 ms |
14400 KB |
Output is correct |
7 |
Correct |
47 ms |
18256 KB |
Output is correct |
8 |
Correct |
61 ms |
22220 KB |
Output is correct |
9 |
Correct |
61 ms |
22204 KB |
Output is correct |
10 |
Correct |
62 ms |
22096 KB |
Output is correct |
11 |
Correct |
3 ms |
6484 KB |
Output is correct |
12 |
Correct |
67 ms |
22216 KB |
Output is correct |
13 |
Correct |
70 ms |
22108 KB |
Output is correct |
14 |
Correct |
61 ms |
22176 KB |
Output is correct |
15 |
Correct |
59 ms |
22100 KB |
Output is correct |
16 |
Correct |
63 ms |
22364 KB |
Output is correct |
17 |
Correct |
66 ms |
22220 KB |
Output is correct |
18 |
Correct |
62 ms |
22108 KB |
Output is correct |
19 |
Correct |
60 ms |
22104 KB |
Output is correct |
20 |
Correct |
80 ms |
29508 KB |
Output is correct |
21 |
Correct |
3 ms |
6484 KB |
Output is correct |
22 |
Correct |
3 ms |
6484 KB |
Output is correct |
23 |
Correct |
3 ms |
6484 KB |
Output is correct |
24 |
Correct |
118 ms |
18232 KB |
Output is correct |
25 |
Correct |
122 ms |
18256 KB |
Output is correct |
26 |
Correct |
147 ms |
18276 KB |
Output is correct |
27 |
Correct |
120 ms |
18168 KB |
Output is correct |
28 |
Correct |
116 ms |
18240 KB |
Output is correct |
29 |
Correct |
128 ms |
18372 KB |
Output is correct |
30 |
Correct |
119 ms |
18256 KB |
Output is correct |
31 |
Correct |
124 ms |
18292 KB |
Output is correct |
32 |
Correct |
3 ms |
6484 KB |
Output is correct |
33 |
Correct |
3 ms |
6484 KB |
Output is correct |
34 |
Correct |
3 ms |
6484 KB |
Output is correct |
35 |
Correct |
3 ms |
6608 KB |
Output is correct |
36 |
Correct |
6 ms |
7124 KB |
Output is correct |
37 |
Correct |
129 ms |
18184 KB |
Output is correct |
38 |
Correct |
124 ms |
18252 KB |
Output is correct |
39 |
Correct |
120 ms |
18244 KB |
Output is correct |
40 |
Correct |
118 ms |
18196 KB |
Output is correct |
41 |
Correct |
3 ms |
6484 KB |
Output is correct |
42 |
Correct |
3 ms |
6612 KB |
Output is correct |
43 |
Correct |
7 ms |
7116 KB |
Output is correct |
44 |
Correct |
7 ms |
7124 KB |
Output is correct |
45 |
Correct |
123 ms |
18248 KB |
Output is correct |
46 |
Correct |
124 ms |
18220 KB |
Output is correct |
47 |
Correct |
120 ms |
18240 KB |
Output is correct |
48 |
Correct |
122 ms |
18364 KB |
Output is correct |
49 |
Correct |
126 ms |
18272 KB |
Output is correct |
50 |
Correct |
167 ms |
18276 KB |
Output is correct |
51 |
Correct |
134 ms |
18240 KB |
Output is correct |
52 |
Correct |
125 ms |
18212 KB |
Output is correct |
53 |
Correct |
118 ms |
18240 KB |
Output is correct |
54 |
Correct |
120 ms |
18212 KB |
Output is correct |
55 |
Correct |
120 ms |
18260 KB |
Output is correct |
56 |
Correct |
3 ms |
6484 KB |
Output is correct |
57 |
Correct |
62 ms |
22184 KB |
Output is correct |
58 |
Correct |
62 ms |
22212 KB |
Output is correct |
59 |
Correct |
61 ms |
22212 KB |
Output is correct |
60 |
Correct |
3 ms |
6496 KB |
Output is correct |
61 |
Correct |
3 ms |
6484 KB |
Output is correct |
62 |
Correct |
3 ms |
6484 KB |
Output is correct |
63 |
Correct |
3 ms |
6484 KB |
Output is correct |
64 |
Correct |
3 ms |
6484 KB |
Output is correct |
65 |
Correct |
3 ms |
6484 KB |
Output is correct |
66 |
Correct |
3 ms |
6484 KB |
Output is correct |
67 |
Correct |
3 ms |
6484 KB |
Output is correct |
68 |
Correct |
3 ms |
6484 KB |
Output is correct |
69 |
Correct |
3 ms |
6576 KB |
Output is correct |
70 |
Correct |
3 ms |
6576 KB |
Output is correct |
71 |
Correct |
3 ms |
6484 KB |
Output is correct |
72 |
Correct |
3 ms |
6484 KB |
Output is correct |
73 |
Correct |
3 ms |
6484 KB |
Output is correct |
74 |
Correct |
4 ms |
6612 KB |
Output is correct |
75 |
Correct |
3 ms |
6484 KB |
Output is correct |
76 |
Correct |
3 ms |
6580 KB |
Output is correct |
77 |
Correct |
4 ms |
6484 KB |
Output is correct |
78 |
Correct |
4 ms |
6580 KB |
Output is correct |
79 |
Correct |
3 ms |
6484 KB |
Output is correct |
80 |
Correct |
3 ms |
6580 KB |
Output is correct |
81 |
Correct |
3 ms |
6580 KB |
Output is correct |
82 |
Correct |
3 ms |
6484 KB |
Output is correct |
83 |
Correct |
3 ms |
6580 KB |
Output is correct |
84 |
Correct |
3 ms |
6484 KB |
Output is correct |
85 |
Correct |
3 ms |
6484 KB |
Output is correct |
86 |
Correct |
3 ms |
6484 KB |
Output is correct |
87 |
Correct |
3 ms |
6484 KB |
Output is correct |
88 |
Correct |
5 ms |
6980 KB |
Output is correct |
89 |
Correct |
6 ms |
7152 KB |
Output is correct |
90 |
Correct |
7 ms |
7312 KB |
Output is correct |
91 |
Correct |
24 ms |
10812 KB |
Output is correct |
92 |
Correct |
44 ms |
14900 KB |
Output is correct |
93 |
Correct |
125 ms |
23240 KB |
Output is correct |
94 |
Correct |
104 ms |
23232 KB |
Output is correct |
95 |
Correct |
100 ms |
23228 KB |
Output is correct |
96 |
Correct |
100 ms |
23300 KB |
Output is correct |
97 |
Correct |
101 ms |
22628 KB |
Output is correct |
98 |
Correct |
99 ms |
23676 KB |
Output is correct |
99 |
Correct |
105 ms |
22600 KB |
Output is correct |
100 |
Correct |
111 ms |
23304 KB |
Output is correct |
101 |
Correct |
122 ms |
23992 KB |
Output is correct |
102 |
Correct |
117 ms |
23476 KB |
Output is correct |
103 |
Correct |
92 ms |
22972 KB |
Output is correct |
104 |
Correct |
89 ms |
23500 KB |
Output is correct |
105 |
Correct |
109 ms |
23612 KB |
Output is correct |
106 |
Correct |
104 ms |
20956 KB |
Output is correct |