//#include "job.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7;
struct comp {
bool operator()(pair<pair<ll,ll>,int>a, pair<pair<ll,ll>,int>b) {
return a.st.st*b.st.nd>=a.st.nd*b.st.st;
}
};
priority_queue<pair<pair<ll,ll>,int>,vector<pair<pair<ll,ll>,int>>,comp>q;
int F[LIM], odw[LIM], n;
ll ans, aktt;
pair<ll,ll>T[LIM];
int fnd(int x) {
if(F[x]==x) return x;
return F[x]=fnd(F[x]);
}
ll scheduling_cost(vector<int>P, vector<int>U, vector<int>D) {
n=P.size();
rep(i, n) {
T[i]={D[i], U[i]};
F[i]=i;
q.push({T[i], i});
}
while(!q.empty()) {
pair<ll,ll>x=q.top().st;
int p=q.top().nd; q.pop();
if(odw[p]) continue;
odw[p]=1;
if(P[p]==-1 || odw[fnd(P[p])]) {
aktt+=x.st;
ans+=aktt*x.nd;
continue;
}
int a=fnd(P[p]);
ans-=T[a].nd*T[p].st;
T[a].st+=T[p].st;
T[a].nd+=T[p].nd;
F[p]=a;
q.push({T[a], a});
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
38 ms |
4728 KB |
Output is correct |
6 |
Correct |
86 ms |
9024 KB |
Output is correct |
7 |
Correct |
121 ms |
15020 KB |
Output is correct |
8 |
Correct |
174 ms |
17712 KB |
Output is correct |
9 |
Correct |
229 ms |
17712 KB |
Output is correct |
10 |
Correct |
182 ms |
17704 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
182 ms |
17716 KB |
Output is correct |
13 |
Correct |
148 ms |
17704 KB |
Output is correct |
14 |
Correct |
153 ms |
17600 KB |
Output is correct |
15 |
Correct |
127 ms |
17588 KB |
Output is correct |
16 |
Correct |
138 ms |
17640 KB |
Output is correct |
17 |
Correct |
205 ms |
17704 KB |
Output is correct |
18 |
Correct |
172 ms |
17600 KB |
Output is correct |
19 |
Correct |
120 ms |
17580 KB |
Output is correct |
20 |
Correct |
124 ms |
17608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
94 ms |
16164 KB |
Output is correct |
5 |
Correct |
93 ms |
16208 KB |
Output is correct |
6 |
Correct |
113 ms |
16160 KB |
Output is correct |
7 |
Correct |
99 ms |
16160 KB |
Output is correct |
8 |
Correct |
94 ms |
16384 KB |
Output is correct |
9 |
Correct |
95 ms |
16176 KB |
Output is correct |
10 |
Correct |
91 ms |
16264 KB |
Output is correct |
11 |
Correct |
104 ms |
16280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
5 ms |
1304 KB |
Output is correct |
6 |
Correct |
99 ms |
16860 KB |
Output is correct |
7 |
Correct |
95 ms |
16816 KB |
Output is correct |
8 |
Correct |
97 ms |
16716 KB |
Output is correct |
9 |
Correct |
106 ms |
16820 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
1300 KB |
Output is correct |
13 |
Correct |
5 ms |
1304 KB |
Output is correct |
14 |
Correct |
100 ms |
16832 KB |
Output is correct |
15 |
Correct |
95 ms |
16808 KB |
Output is correct |
16 |
Correct |
111 ms |
16808 KB |
Output is correct |
17 |
Correct |
96 ms |
16748 KB |
Output is correct |
18 |
Correct |
100 ms |
16956 KB |
Output is correct |
19 |
Correct |
97 ms |
16836 KB |
Output is correct |
20 |
Correct |
93 ms |
16804 KB |
Output is correct |
21 |
Correct |
102 ms |
16836 KB |
Output is correct |
22 |
Correct |
97 ms |
16840 KB |
Output is correct |
23 |
Correct |
102 ms |
16888 KB |
Output is correct |
24 |
Correct |
93 ms |
16840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
216 ms |
17712 KB |
Output is correct |
3 |
Correct |
180 ms |
17616 KB |
Output is correct |
4 |
Correct |
188 ms |
17712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
38 ms |
4728 KB |
Output is correct |
6 |
Correct |
86 ms |
9024 KB |
Output is correct |
7 |
Correct |
121 ms |
15020 KB |
Output is correct |
8 |
Correct |
174 ms |
17712 KB |
Output is correct |
9 |
Correct |
229 ms |
17712 KB |
Output is correct |
10 |
Correct |
182 ms |
17704 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
182 ms |
17716 KB |
Output is correct |
13 |
Correct |
148 ms |
17704 KB |
Output is correct |
14 |
Correct |
153 ms |
17600 KB |
Output is correct |
15 |
Correct |
127 ms |
17588 KB |
Output is correct |
16 |
Correct |
138 ms |
17640 KB |
Output is correct |
17 |
Correct |
205 ms |
17704 KB |
Output is correct |
18 |
Correct |
172 ms |
17600 KB |
Output is correct |
19 |
Correct |
120 ms |
17580 KB |
Output is correct |
20 |
Correct |
124 ms |
17608 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
304 KB |
Output is correct |
24 |
Correct |
94 ms |
16164 KB |
Output is correct |
25 |
Correct |
93 ms |
16208 KB |
Output is correct |
26 |
Correct |
113 ms |
16160 KB |
Output is correct |
27 |
Correct |
99 ms |
16160 KB |
Output is correct |
28 |
Correct |
94 ms |
16384 KB |
Output is correct |
29 |
Correct |
95 ms |
16176 KB |
Output is correct |
30 |
Correct |
91 ms |
16264 KB |
Output is correct |
31 |
Correct |
104 ms |
16280 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
1304 KB |
Output is correct |
37 |
Correct |
99 ms |
16860 KB |
Output is correct |
38 |
Correct |
95 ms |
16816 KB |
Output is correct |
39 |
Correct |
97 ms |
16716 KB |
Output is correct |
40 |
Correct |
106 ms |
16820 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
4 ms |
1300 KB |
Output is correct |
44 |
Correct |
5 ms |
1304 KB |
Output is correct |
45 |
Correct |
100 ms |
16832 KB |
Output is correct |
46 |
Correct |
95 ms |
16808 KB |
Output is correct |
47 |
Correct |
111 ms |
16808 KB |
Output is correct |
48 |
Correct |
96 ms |
16748 KB |
Output is correct |
49 |
Correct |
100 ms |
16956 KB |
Output is correct |
50 |
Correct |
97 ms |
16836 KB |
Output is correct |
51 |
Correct |
93 ms |
16804 KB |
Output is correct |
52 |
Correct |
102 ms |
16836 KB |
Output is correct |
53 |
Correct |
97 ms |
16840 KB |
Output is correct |
54 |
Correct |
102 ms |
16888 KB |
Output is correct |
55 |
Correct |
93 ms |
16840 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
216 ms |
17712 KB |
Output is correct |
58 |
Correct |
180 ms |
17616 KB |
Output is correct |
59 |
Correct |
188 ms |
17712 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
1 ms |
212 KB |
Output is correct |
62 |
Correct |
1 ms |
312 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
0 ms |
212 KB |
Output is correct |
67 |
Correct |
1 ms |
212 KB |
Output is correct |
68 |
Correct |
0 ms |
212 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
1 ms |
308 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
0 ms |
308 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
340 KB |
Output is correct |
76 |
Correct |
1 ms |
340 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
308 KB |
Output is correct |
80 |
Correct |
0 ms |
300 KB |
Output is correct |
81 |
Correct |
0 ms |
212 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
0 ms |
212 KB |
Output is correct |
84 |
Correct |
0 ms |
308 KB |
Output is correct |
85 |
Correct |
0 ms |
212 KB |
Output is correct |
86 |
Correct |
0 ms |
212 KB |
Output is correct |
87 |
Correct |
0 ms |
212 KB |
Output is correct |
88 |
Correct |
3 ms |
852 KB |
Output is correct |
89 |
Correct |
5 ms |
1064 KB |
Output is correct |
90 |
Correct |
6 ms |
1304 KB |
Output is correct |
91 |
Correct |
38 ms |
4656 KB |
Output is correct |
92 |
Correct |
75 ms |
8880 KB |
Output is correct |
93 |
Correct |
160 ms |
17600 KB |
Output is correct |
94 |
Correct |
156 ms |
17584 KB |
Output is correct |
95 |
Correct |
141 ms |
17604 KB |
Output is correct |
96 |
Correct |
187 ms |
17704 KB |
Output is correct |
97 |
Correct |
142 ms |
17544 KB |
Output is correct |
98 |
Correct |
139 ms |
17696 KB |
Output is correct |
99 |
Correct |
120 ms |
17468 KB |
Output is correct |
100 |
Correct |
187 ms |
17704 KB |
Output is correct |
101 |
Correct |
169 ms |
17708 KB |
Output is correct |
102 |
Correct |
106 ms |
17612 KB |
Output is correct |
103 |
Correct |
157 ms |
17608 KB |
Output is correct |
104 |
Correct |
169 ms |
17880 KB |
Output is correct |
105 |
Correct |
124 ms |
17604 KB |
Output is correct |
106 |
Correct |
98 ms |
17076 KB |
Output is correct |