/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
#include "job.h"
using namespace std;
typedef long long ll;
const int N_MAX = 200002;
int n;
struct Cost
{
int d, u;
};
Cost cost[N_MAX];
int parent[N_MAX];
vector <int> sons[N_MAX];
bool operator < (const Cost &a, const Cost &b)
{
return a.d * b.u < b.d * a.u;
}
struct Node
{
int u;
Cost c;
};
bool operator < (const Node &u, const Node &v)
{
return make_pair(u.c, u.u) > make_pair(v.c, v.u);
}
set <Node> notJoined[N_MAX];
void mergeSets (set <Node> &in, set <Node> &from)
{
if(in.size() < from.size())
swap(in, from);
while(from.empty() == false)
{
in.insert(*from.begin());
from.erase(from.begin());
}
}
bool isRoot[N_MAX];
void dfs (int u)
{
for(int v : sons[u])
{
dfs(v);
notJoined[u].insert(Node{v, cost[v]});
}
isRoot[u] = true;
while(notJoined[u].empty() == false)
{
int v = notJoined[u].begin()->u;
if(!(cost[v] < cost[u]))
break;
notJoined[u].erase(notJoined[u].begin());
isRoot[v] = false;
cost[u].d += cost[v].d;
cost[u].u += cost[v].u;
mergeSets(notJoined[u], notJoined[v]);
}
}
int order[N_MAX];
int curr;
void solveOne (int u)
{
order[++curr] = u;
vector <pair <Cost, int> > aux;
for(int v : sons[u])
if(isRoot[v] == false)
aux.push_back(make_pair(cost[v], v));
sort(aux.begin(), aux.end());
for(pair <Cost, int> p : aux)
solveOne(p.second);
}
void solveAll (int u)
{
solveOne(u);
vector <int> aux;
while(notJoined[u].empty() == false)
{
int v = notJoined[u].begin()->u;
notJoined[u].erase(notJoined[u].begin());
aux.push_back(v);
}
reverse(aux.begin(), aux.end());
for(int v : aux)
solveAll(v);
}
ll scheduling_cost (vector <int> p, vector <int> u, vector <int> d)
{
n = p.size();
for(int i = 1; i <= n; i++)
{
parent[i] = p[i - 1] + 1;
cost[i] = Cost{d[i - 1], u[i - 1]};
}
for(int i = 2; i <= n; i++)
sons[parent[i]].push_back(i);
dfs(1);
solveAll(1);
int currTime = 0;
ll ans = 0;
for(int i = 1; i <= n; i++)
{
int j = order[i];
currTime += d[j - 1];
ans += 1LL * currTime * u[j - 1];
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
11 ms |
14572 KB |
Output is correct |
5 |
Correct |
42 ms |
25188 KB |
Output is correct |
6 |
Correct |
73 ms |
35940 KB |
Output is correct |
7 |
Correct |
108 ms |
46564 KB |
Output is correct |
8 |
Correct |
142 ms |
57188 KB |
Output is correct |
9 |
Correct |
139 ms |
57112 KB |
Output is correct |
10 |
Correct |
137 ms |
57188 KB |
Output is correct |
11 |
Correct |
10 ms |
14444 KB |
Output is correct |
12 |
Correct |
142 ms |
57316 KB |
Output is correct |
13 |
Correct |
140 ms |
57316 KB |
Output is correct |
14 |
Correct |
137 ms |
57316 KB |
Output is correct |
15 |
Correct |
144 ms |
57604 KB |
Output is correct |
16 |
Correct |
139 ms |
57316 KB |
Output is correct |
17 |
Correct |
137 ms |
57188 KB |
Output is correct |
18 |
Correct |
139 ms |
57188 KB |
Output is correct |
19 |
Correct |
153 ms |
63080 KB |
Output is correct |
20 |
Correct |
151 ms |
65636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
265 ms |
36824 KB |
Output is correct |
5 |
Correct |
279 ms |
36824 KB |
Output is correct |
6 |
Correct |
281 ms |
36692 KB |
Output is correct |
7 |
Correct |
267 ms |
36704 KB |
Output is correct |
8 |
Correct |
270 ms |
36696 KB |
Output is correct |
9 |
Correct |
265 ms |
36700 KB |
Output is correct |
10 |
Correct |
266 ms |
36824 KB |
Output is correct |
11 |
Correct |
291 ms |
36804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
11 ms |
14572 KB |
Output is correct |
5 |
Correct |
17 ms |
15596 KB |
Output is correct |
6 |
Correct |
254 ms |
36764 KB |
Output is correct |
7 |
Correct |
258 ms |
36800 KB |
Output is correct |
8 |
Correct |
253 ms |
36716 KB |
Output is correct |
9 |
Correct |
253 ms |
36696 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
11 ms |
14572 KB |
Output is correct |
12 |
Correct |
16 ms |
15468 KB |
Output is correct |
13 |
Correct |
17 ms |
15596 KB |
Output is correct |
14 |
Correct |
275 ms |
36700 KB |
Output is correct |
15 |
Correct |
250 ms |
36696 KB |
Output is correct |
16 |
Correct |
268 ms |
36696 KB |
Output is correct |
17 |
Correct |
255 ms |
36916 KB |
Output is correct |
18 |
Correct |
258 ms |
36624 KB |
Output is correct |
19 |
Correct |
256 ms |
36952 KB |
Output is correct |
20 |
Correct |
264 ms |
36828 KB |
Output is correct |
21 |
Correct |
262 ms |
36696 KB |
Output is correct |
22 |
Correct |
258 ms |
36700 KB |
Output is correct |
23 |
Correct |
253 ms |
36696 KB |
Output is correct |
24 |
Correct |
251 ms |
36696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Incorrect |
135 ms |
46308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Incorrect |
10 ms |
14444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
11 ms |
14572 KB |
Output is correct |
5 |
Correct |
42 ms |
25188 KB |
Output is correct |
6 |
Correct |
73 ms |
35940 KB |
Output is correct |
7 |
Correct |
108 ms |
46564 KB |
Output is correct |
8 |
Correct |
142 ms |
57188 KB |
Output is correct |
9 |
Correct |
139 ms |
57112 KB |
Output is correct |
10 |
Correct |
137 ms |
57188 KB |
Output is correct |
11 |
Correct |
10 ms |
14444 KB |
Output is correct |
12 |
Correct |
142 ms |
57316 KB |
Output is correct |
13 |
Correct |
140 ms |
57316 KB |
Output is correct |
14 |
Correct |
137 ms |
57316 KB |
Output is correct |
15 |
Correct |
144 ms |
57604 KB |
Output is correct |
16 |
Correct |
139 ms |
57316 KB |
Output is correct |
17 |
Correct |
137 ms |
57188 KB |
Output is correct |
18 |
Correct |
139 ms |
57188 KB |
Output is correct |
19 |
Correct |
153 ms |
63080 KB |
Output is correct |
20 |
Correct |
151 ms |
65636 KB |
Output is correct |
21 |
Correct |
10 ms |
14444 KB |
Output is correct |
22 |
Correct |
10 ms |
14444 KB |
Output is correct |
23 |
Correct |
10 ms |
14444 KB |
Output is correct |
24 |
Correct |
265 ms |
36824 KB |
Output is correct |
25 |
Correct |
279 ms |
36824 KB |
Output is correct |
26 |
Correct |
281 ms |
36692 KB |
Output is correct |
27 |
Correct |
267 ms |
36704 KB |
Output is correct |
28 |
Correct |
270 ms |
36696 KB |
Output is correct |
29 |
Correct |
265 ms |
36700 KB |
Output is correct |
30 |
Correct |
266 ms |
36824 KB |
Output is correct |
31 |
Correct |
291 ms |
36804 KB |
Output is correct |
32 |
Correct |
10 ms |
14444 KB |
Output is correct |
33 |
Correct |
10 ms |
14444 KB |
Output is correct |
34 |
Correct |
10 ms |
14444 KB |
Output is correct |
35 |
Correct |
11 ms |
14572 KB |
Output is correct |
36 |
Correct |
17 ms |
15596 KB |
Output is correct |
37 |
Correct |
254 ms |
36764 KB |
Output is correct |
38 |
Correct |
258 ms |
36800 KB |
Output is correct |
39 |
Correct |
253 ms |
36716 KB |
Output is correct |
40 |
Correct |
253 ms |
36696 KB |
Output is correct |
41 |
Correct |
10 ms |
14444 KB |
Output is correct |
42 |
Correct |
11 ms |
14572 KB |
Output is correct |
43 |
Correct |
16 ms |
15468 KB |
Output is correct |
44 |
Correct |
17 ms |
15596 KB |
Output is correct |
45 |
Correct |
275 ms |
36700 KB |
Output is correct |
46 |
Correct |
250 ms |
36696 KB |
Output is correct |
47 |
Correct |
268 ms |
36696 KB |
Output is correct |
48 |
Correct |
255 ms |
36916 KB |
Output is correct |
49 |
Correct |
258 ms |
36624 KB |
Output is correct |
50 |
Correct |
256 ms |
36952 KB |
Output is correct |
51 |
Correct |
264 ms |
36828 KB |
Output is correct |
52 |
Correct |
262 ms |
36696 KB |
Output is correct |
53 |
Correct |
258 ms |
36700 KB |
Output is correct |
54 |
Correct |
253 ms |
36696 KB |
Output is correct |
55 |
Correct |
251 ms |
36696 KB |
Output is correct |
56 |
Correct |
10 ms |
14444 KB |
Output is correct |
57 |
Incorrect |
135 ms |
46308 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |