// model_solution/job-mruxim.cpp
// ... ... .. ....!
// ... ....... .... ...!
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##__n = (int)(n); i < i##__n; ++i)
#define fer(i, a, b) for(int i = (int)(a), i##__b = (int)(b); i < i##__b; ++i)
#define rof(i, b, a) for(int i = (int)(b), i##__a = (int)(a); i-- > i##__a; )
#define sz(x) (int((x).size()))
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
//#define endl '\n'
template<class P, class Q> inline void smin(P &a, Q b) { if (b < a) a = b; }
template<class P, class Q> inline void smax(P &a, Q b) { if (a < b) a = b; }
typedef long long ll;
typedef pair<int, int> pii;
////////////////////////////////////////////////////////////////////////////////
const int maxn = 200000 + 100;
int par[maxn];
struct Job {
ll urg, dur;
bool operator<(Job j) const {
// return urg * j.dur > j.urg * dur;
return urg / (double)dur > j.urg / (double)j.dur;
}
} jobs[maxn];
vector<int> child[maxn];
multiset<Job> path[maxn];
ll ans;
void dfs(int u) {
int big = -1;
for(int v: child[u]) {
dfs(v);
if(big == -1 || sz(path[v]) > sz(path[big]))
big = v;
}
if(big != -1)
path[u] = move(path[big]);
for(int v: child[u])
if(v != big)
for(Job j: path[v])
path[u].insert(j);
Job cur = jobs[u];
while(!path[u].empty() && *path[u].begin() < cur)
ans += cur.dur * path[u].begin()->urg,
cur.urg += path[u].begin()->urg,
cur.dur += path[u].begin()->dur,
path[u].erase(path[u].begin());
path[u].insert(cur);
}
long long scheduling_cost(vector<int> P, vector<int> U, vector<int> D) {
int n = sz(U);
rep(i, n) jobs[i].urg = U[i], jobs[i].dur = D[i];
int root = -1;
rep(i, n) {
par[i] = P[i];
if(par[i] == -1)
root = i;
else
child[par[i]].pb(i);
}
dfs(root);
ll c_time = 0;
for(Job j: path[root])
ans += c_time * j.urg,
c_time += j.dur;
rep(i, n) ans += U[i] * D[i];
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
14456 KB |
Output is correct |
2 |
Correct |
15 ms |
14372 KB |
Output is correct |
3 |
Correct |
15 ms |
14388 KB |
Output is correct |
4 |
Correct |
15 ms |
14592 KB |
Output is correct |
5 |
Correct |
50 ms |
24412 KB |
Output is correct |
6 |
Correct |
85 ms |
34412 KB |
Output is correct |
7 |
Correct |
120 ms |
44348 KB |
Output is correct |
8 |
Correct |
161 ms |
54332 KB |
Output is correct |
9 |
Correct |
207 ms |
54364 KB |
Output is correct |
10 |
Correct |
157 ms |
54520 KB |
Output is correct |
11 |
Correct |
18 ms |
14400 KB |
Output is correct |
12 |
Correct |
159 ms |
54392 KB |
Output is correct |
13 |
Correct |
151 ms |
54392 KB |
Output is correct |
14 |
Correct |
159 ms |
54392 KB |
Output is correct |
15 |
Correct |
149 ms |
54392 KB |
Output is correct |
16 |
Correct |
171 ms |
54508 KB |
Output is correct |
17 |
Correct |
160 ms |
54392 KB |
Output is correct |
18 |
Correct |
156 ms |
54392 KB |
Output is correct |
19 |
Correct |
148 ms |
54300 KB |
Output is correct |
20 |
Correct |
200 ms |
63040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14456 KB |
Output is correct |
2 |
Correct |
14 ms |
14456 KB |
Output is correct |
3 |
Correct |
15 ms |
14456 KB |
Output is correct |
4 |
Correct |
288 ms |
48848 KB |
Output is correct |
5 |
Correct |
286 ms |
48876 KB |
Output is correct |
6 |
Correct |
289 ms |
48876 KB |
Output is correct |
7 |
Correct |
282 ms |
48936 KB |
Output is correct |
8 |
Correct |
285 ms |
48988 KB |
Output is correct |
9 |
Correct |
303 ms |
49016 KB |
Output is correct |
10 |
Correct |
294 ms |
49016 KB |
Output is correct |
11 |
Correct |
288 ms |
48876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
14456 KB |
Output is correct |
2 |
Correct |
15 ms |
14456 KB |
Output is correct |
3 |
Correct |
15 ms |
14456 KB |
Output is correct |
4 |
Correct |
16 ms |
14584 KB |
Output is correct |
5 |
Correct |
24 ms |
16120 KB |
Output is correct |
6 |
Correct |
299 ms |
48984 KB |
Output is correct |
7 |
Correct |
299 ms |
48876 KB |
Output is correct |
8 |
Correct |
295 ms |
48876 KB |
Output is correct |
9 |
Correct |
290 ms |
48876 KB |
Output is correct |
10 |
Correct |
16 ms |
14456 KB |
Output is correct |
11 |
Correct |
16 ms |
14716 KB |
Output is correct |
12 |
Correct |
23 ms |
15992 KB |
Output is correct |
13 |
Correct |
25 ms |
16120 KB |
Output is correct |
14 |
Correct |
298 ms |
48920 KB |
Output is correct |
15 |
Correct |
288 ms |
48972 KB |
Output is correct |
16 |
Correct |
305 ms |
48876 KB |
Output is correct |
17 |
Correct |
290 ms |
49004 KB |
Output is correct |
18 |
Correct |
298 ms |
49132 KB |
Output is correct |
19 |
Correct |
294 ms |
48888 KB |
Output is correct |
20 |
Correct |
302 ms |
48876 KB |
Output is correct |
21 |
Correct |
296 ms |
48876 KB |
Output is correct |
22 |
Correct |
292 ms |
49004 KB |
Output is correct |
23 |
Correct |
309 ms |
49004 KB |
Output is correct |
24 |
Correct |
288 ms |
48932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
14456 KB |
Output is correct |
2 |
Correct |
148 ms |
41856 KB |
Output is correct |
3 |
Correct |
150 ms |
41848 KB |
Output is correct |
4 |
Correct |
150 ms |
41880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
14456 KB |
Output is correct |
2 |
Correct |
15 ms |
14460 KB |
Output is correct |
3 |
Correct |
15 ms |
14456 KB |
Output is correct |
4 |
Correct |
15 ms |
14584 KB |
Output is correct |
5 |
Correct |
15 ms |
14456 KB |
Output is correct |
6 |
Correct |
15 ms |
14456 KB |
Output is correct |
7 |
Correct |
15 ms |
14456 KB |
Output is correct |
8 |
Correct |
15 ms |
14460 KB |
Output is correct |
9 |
Correct |
15 ms |
14456 KB |
Output is correct |
10 |
Correct |
15 ms |
14444 KB |
Output is correct |
11 |
Correct |
15 ms |
14456 KB |
Output is correct |
12 |
Correct |
15 ms |
14456 KB |
Output is correct |
13 |
Correct |
15 ms |
14456 KB |
Output is correct |
14 |
Correct |
16 ms |
14456 KB |
Output is correct |
15 |
Correct |
15 ms |
14456 KB |
Output is correct |
16 |
Correct |
14 ms |
14456 KB |
Output is correct |
17 |
Correct |
15 ms |
14456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
14456 KB |
Output is correct |
2 |
Correct |
15 ms |
14372 KB |
Output is correct |
3 |
Correct |
15 ms |
14388 KB |
Output is correct |
4 |
Correct |
15 ms |
14592 KB |
Output is correct |
5 |
Correct |
50 ms |
24412 KB |
Output is correct |
6 |
Correct |
85 ms |
34412 KB |
Output is correct |
7 |
Correct |
120 ms |
44348 KB |
Output is correct |
8 |
Correct |
161 ms |
54332 KB |
Output is correct |
9 |
Correct |
207 ms |
54364 KB |
Output is correct |
10 |
Correct |
157 ms |
54520 KB |
Output is correct |
11 |
Correct |
18 ms |
14400 KB |
Output is correct |
12 |
Correct |
159 ms |
54392 KB |
Output is correct |
13 |
Correct |
151 ms |
54392 KB |
Output is correct |
14 |
Correct |
159 ms |
54392 KB |
Output is correct |
15 |
Correct |
149 ms |
54392 KB |
Output is correct |
16 |
Correct |
171 ms |
54508 KB |
Output is correct |
17 |
Correct |
160 ms |
54392 KB |
Output is correct |
18 |
Correct |
156 ms |
54392 KB |
Output is correct |
19 |
Correct |
148 ms |
54300 KB |
Output is correct |
20 |
Correct |
200 ms |
63040 KB |
Output is correct |
21 |
Correct |
14 ms |
14456 KB |
Output is correct |
22 |
Correct |
14 ms |
14456 KB |
Output is correct |
23 |
Correct |
15 ms |
14456 KB |
Output is correct |
24 |
Correct |
288 ms |
48848 KB |
Output is correct |
25 |
Correct |
286 ms |
48876 KB |
Output is correct |
26 |
Correct |
289 ms |
48876 KB |
Output is correct |
27 |
Correct |
282 ms |
48936 KB |
Output is correct |
28 |
Correct |
285 ms |
48988 KB |
Output is correct |
29 |
Correct |
303 ms |
49016 KB |
Output is correct |
30 |
Correct |
294 ms |
49016 KB |
Output is correct |
31 |
Correct |
288 ms |
48876 KB |
Output is correct |
32 |
Correct |
15 ms |
14456 KB |
Output is correct |
33 |
Correct |
15 ms |
14456 KB |
Output is correct |
34 |
Correct |
15 ms |
14456 KB |
Output is correct |
35 |
Correct |
16 ms |
14584 KB |
Output is correct |
36 |
Correct |
24 ms |
16120 KB |
Output is correct |
37 |
Correct |
299 ms |
48984 KB |
Output is correct |
38 |
Correct |
299 ms |
48876 KB |
Output is correct |
39 |
Correct |
295 ms |
48876 KB |
Output is correct |
40 |
Correct |
290 ms |
48876 KB |
Output is correct |
41 |
Correct |
16 ms |
14456 KB |
Output is correct |
42 |
Correct |
16 ms |
14716 KB |
Output is correct |
43 |
Correct |
23 ms |
15992 KB |
Output is correct |
44 |
Correct |
25 ms |
16120 KB |
Output is correct |
45 |
Correct |
298 ms |
48920 KB |
Output is correct |
46 |
Correct |
288 ms |
48972 KB |
Output is correct |
47 |
Correct |
305 ms |
48876 KB |
Output is correct |
48 |
Correct |
290 ms |
49004 KB |
Output is correct |
49 |
Correct |
298 ms |
49132 KB |
Output is correct |
50 |
Correct |
294 ms |
48888 KB |
Output is correct |
51 |
Correct |
302 ms |
48876 KB |
Output is correct |
52 |
Correct |
296 ms |
48876 KB |
Output is correct |
53 |
Correct |
292 ms |
49004 KB |
Output is correct |
54 |
Correct |
309 ms |
49004 KB |
Output is correct |
55 |
Correct |
288 ms |
48932 KB |
Output is correct |
56 |
Correct |
12 ms |
14456 KB |
Output is correct |
57 |
Correct |
148 ms |
41856 KB |
Output is correct |
58 |
Correct |
150 ms |
41848 KB |
Output is correct |
59 |
Correct |
150 ms |
41880 KB |
Output is correct |
60 |
Correct |
15 ms |
14456 KB |
Output is correct |
61 |
Correct |
15 ms |
14460 KB |
Output is correct |
62 |
Correct |
15 ms |
14456 KB |
Output is correct |
63 |
Correct |
15 ms |
14584 KB |
Output is correct |
64 |
Correct |
15 ms |
14456 KB |
Output is correct |
65 |
Correct |
15 ms |
14456 KB |
Output is correct |
66 |
Correct |
15 ms |
14456 KB |
Output is correct |
67 |
Correct |
15 ms |
14460 KB |
Output is correct |
68 |
Correct |
15 ms |
14456 KB |
Output is correct |
69 |
Correct |
15 ms |
14444 KB |
Output is correct |
70 |
Correct |
15 ms |
14456 KB |
Output is correct |
71 |
Correct |
15 ms |
14456 KB |
Output is correct |
72 |
Correct |
15 ms |
14456 KB |
Output is correct |
73 |
Correct |
16 ms |
14456 KB |
Output is correct |
74 |
Correct |
15 ms |
14456 KB |
Output is correct |
75 |
Correct |
14 ms |
14456 KB |
Output is correct |
76 |
Correct |
15 ms |
14456 KB |
Output is correct |
77 |
Correct |
15 ms |
14456 KB |
Output is correct |
78 |
Correct |
15 ms |
14456 KB |
Output is correct |
79 |
Correct |
15 ms |
14456 KB |
Output is correct |
80 |
Correct |
15 ms |
14456 KB |
Output is correct |
81 |
Correct |
15 ms |
14584 KB |
Output is correct |
82 |
Correct |
15 ms |
14456 KB |
Output is correct |
83 |
Correct |
15 ms |
14456 KB |
Output is correct |
84 |
Correct |
15 ms |
14456 KB |
Output is correct |
85 |
Correct |
15 ms |
14456 KB |
Output is correct |
86 |
Correct |
14 ms |
14456 KB |
Output is correct |
87 |
Correct |
15 ms |
14456 KB |
Output is correct |
88 |
Correct |
21 ms |
15352 KB |
Output is correct |
89 |
Correct |
28 ms |
15992 KB |
Output is correct |
90 |
Correct |
31 ms |
16428 KB |
Output is correct |
91 |
Correct |
92 ms |
25592 KB |
Output is correct |
92 |
Correct |
183 ms |
38136 KB |
Output is correct |
93 |
Correct |
412 ms |
62200 KB |
Output is correct |
94 |
Correct |
382 ms |
63352 KB |
Output is correct |
95 |
Correct |
377 ms |
62840 KB |
Output is correct |
96 |
Correct |
410 ms |
62808 KB |
Output is correct |
97 |
Correct |
369 ms |
63608 KB |
Output is correct |
98 |
Correct |
388 ms |
67448 KB |
Output is correct |
99 |
Correct |
427 ms |
74112 KB |
Output is correct |
100 |
Correct |
381 ms |
62584 KB |
Output is correct |
101 |
Correct |
317 ms |
52088 KB |
Output is correct |
102 |
Correct |
531 ms |
90276 KB |
Output is correct |
103 |
Correct |
370 ms |
51640 KB |
Output is correct |
104 |
Correct |
278 ms |
44408 KB |
Output is correct |
105 |
Correct |
210 ms |
40312 KB |
Output is correct |
106 |
Correct |
410 ms |
61048 KB |
Output is correct |