Submission #417400

# Submission time Handle Problem Language Result Execution time Memory
417400 2021-06-03T16:20:06 Z maximath_1 Job Scheduling (IOI19_job) C++17
100 / 100
289 ms 31856 KB
#include "job.h"
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
#define ll long long

struct job{
	int u, d, id;
	bool operator < (const job &rhs) const{
		return d * 1ll * rhs.u > u * 1ll * rhs.d;
	}
};

int par[200005];
int find(int nw){
	return par[nw] = (par[nw] == nw ? nw : find(par[nw]));
}

vector<int> adj[200005], ord;
void dfs(int nw){
	ord.push_back(nw);
	for(int nx : adj[nw]) dfs(nx);
}

long long scheduling_cost(vector<int> p, vector<int> u, vector<int> d){
	int n = p.size();

	vector<int> U = u, D = d;
	for(int i = 0; i < n; i ++)
		par[i] = i;

	priority_queue<job> pq;
	for(int i = 1; i < n; i ++)
		pq.push({u[i], d[i], i});

	for(; pq.size();){
		auto nw = pq.top();
		pq.pop();

		if(make_pair(nw.u, nw.d) != make_pair(U[nw.id], D[nw.id]))
			continue;

		int f = find(p[nw.id]);
		par[nw.id] = f;
		U[f] += U[nw.id];
		D[f] += D[nw.id];
		adj[f].push_back(nw.id);

		if(f) pq.push({U[f], D[f], f});
	}

	dfs(0);

	ll ans = 0ll, tim = 0ll;
	for(int i : ord){
		tim += d[i];
		ans += tim * u[i];
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 5068 KB Output is correct
5 Correct 49 ms 8872 KB Output is correct
6 Correct 101 ms 12680 KB Output is correct
7 Correct 181 ms 16888 KB Output is correct
8 Correct 280 ms 20588 KB Output is correct
9 Correct 246 ms 20660 KB Output is correct
10 Correct 247 ms 20604 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 287 ms 20496 KB Output is correct
13 Correct 191 ms 30336 KB Output is correct
14 Correct 214 ms 20664 KB Output is correct
15 Correct 167 ms 31856 KB Output is correct
16 Correct 193 ms 20588 KB Output is correct
17 Correct 250 ms 20588 KB Output is correct
18 Correct 268 ms 20508 KB Output is correct
19 Correct 170 ms 31748 KB Output is correct
20 Correct 131 ms 18316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 134 ms 16904 KB Output is correct
5 Correct 124 ms 16920 KB Output is correct
6 Correct 142 ms 16924 KB Output is correct
7 Correct 139 ms 16900 KB Output is correct
8 Correct 133 ms 16900 KB Output is correct
9 Correct 134 ms 16952 KB Output is correct
10 Correct 135 ms 16880 KB Output is correct
11 Correct 124 ms 16948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 8 ms 5648 KB Output is correct
6 Correct 140 ms 16952 KB Output is correct
7 Correct 132 ms 16952 KB Output is correct
8 Correct 135 ms 16900 KB Output is correct
9 Correct 142 ms 16952 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 5068 KB Output is correct
12 Correct 9 ms 5580 KB Output is correct
13 Correct 8 ms 5580 KB Output is correct
14 Correct 134 ms 16900 KB Output is correct
15 Correct 157 ms 16968 KB Output is correct
16 Correct 143 ms 16900 KB Output is correct
17 Correct 131 ms 16952 KB Output is correct
18 Correct 130 ms 16900 KB Output is correct
19 Correct 132 ms 16892 KB Output is correct
20 Correct 136 ms 16908 KB Output is correct
21 Correct 131 ms 16900 KB Output is correct
22 Correct 128 ms 16900 KB Output is correct
23 Correct 143 ms 17076 KB Output is correct
24 Correct 139 ms 16908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 289 ms 20512 KB Output is correct
3 Correct 263 ms 20560 KB Output is correct
4 Correct 252 ms 20532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4884 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 5068 KB Output is correct
5 Correct 49 ms 8872 KB Output is correct
6 Correct 101 ms 12680 KB Output is correct
7 Correct 181 ms 16888 KB Output is correct
8 Correct 280 ms 20588 KB Output is correct
9 Correct 246 ms 20660 KB Output is correct
10 Correct 247 ms 20604 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 287 ms 20496 KB Output is correct
13 Correct 191 ms 30336 KB Output is correct
14 Correct 214 ms 20664 KB Output is correct
15 Correct 167 ms 31856 KB Output is correct
16 Correct 193 ms 20588 KB Output is correct
17 Correct 250 ms 20588 KB Output is correct
18 Correct 268 ms 20508 KB Output is correct
19 Correct 170 ms 31748 KB Output is correct
20 Correct 131 ms 18316 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 3 ms 4940 KB Output is correct
24 Correct 134 ms 16904 KB Output is correct
25 Correct 124 ms 16920 KB Output is correct
26 Correct 142 ms 16924 KB Output is correct
27 Correct 139 ms 16900 KB Output is correct
28 Correct 133 ms 16900 KB Output is correct
29 Correct 134 ms 16952 KB Output is correct
30 Correct 135 ms 16880 KB Output is correct
31 Correct 124 ms 16948 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 KB Output is correct
34 Correct 3 ms 4940 KB Output is correct
35 Correct 3 ms 4940 KB Output is correct
36 Correct 8 ms 5648 KB Output is correct
37 Correct 140 ms 16952 KB Output is correct
38 Correct 132 ms 16952 KB Output is correct
39 Correct 135 ms 16900 KB Output is correct
40 Correct 142 ms 16952 KB Output is correct
41 Correct 3 ms 4940 KB Output is correct
42 Correct 4 ms 5068 KB Output is correct
43 Correct 9 ms 5580 KB Output is correct
44 Correct 8 ms 5580 KB Output is correct
45 Correct 134 ms 16900 KB Output is correct
46 Correct 157 ms 16968 KB Output is correct
47 Correct 143 ms 16900 KB Output is correct
48 Correct 131 ms 16952 KB Output is correct
49 Correct 130 ms 16900 KB Output is correct
50 Correct 132 ms 16892 KB Output is correct
51 Correct 136 ms 16908 KB Output is correct
52 Correct 131 ms 16900 KB Output is correct
53 Correct 128 ms 16900 KB Output is correct
54 Correct 143 ms 17076 KB Output is correct
55 Correct 139 ms 16908 KB Output is correct
56 Correct 3 ms 4940 KB Output is correct
57 Correct 289 ms 20512 KB Output is correct
58 Correct 263 ms 20560 KB Output is correct
59 Correct 252 ms 20532 KB Output is correct
60 Correct 3 ms 4940 KB Output is correct
61 Correct 3 ms 4940 KB Output is correct
62 Correct 3 ms 4940 KB Output is correct
63 Correct 3 ms 4940 KB Output is correct
64 Correct 3 ms 4940 KB Output is correct
65 Correct 3 ms 4940 KB Output is correct
66 Correct 3 ms 4884 KB Output is correct
67 Correct 3 ms 4940 KB Output is correct
68 Correct 3 ms 4940 KB Output is correct
69 Correct 3 ms 4940 KB Output is correct
70 Correct 4 ms 4940 KB Output is correct
71 Correct 3 ms 4940 KB Output is correct
72 Correct 3 ms 4940 KB Output is correct
73 Correct 3 ms 4940 KB Output is correct
74 Correct 3 ms 4940 KB Output is correct
75 Correct 3 ms 4940 KB Output is correct
76 Correct 3 ms 4940 KB Output is correct
77 Correct 3 ms 4940 KB Output is correct
78 Correct 3 ms 4940 KB Output is correct
79 Correct 4 ms 4940 KB Output is correct
80 Correct 5 ms 4940 KB Output is correct
81 Correct 3 ms 4940 KB Output is correct
82 Correct 3 ms 4940 KB Output is correct
83 Correct 3 ms 4940 KB Output is correct
84 Correct 3 ms 4940 KB Output is correct
85 Correct 3 ms 4940 KB Output is correct
86 Correct 3 ms 4940 KB Output is correct
87 Correct 3 ms 4940 KB Output is correct
88 Correct 6 ms 5324 KB Output is correct
89 Correct 9 ms 5452 KB Output is correct
90 Correct 10 ms 5648 KB Output is correct
91 Correct 43 ms 8408 KB Output is correct
92 Correct 88 ms 11812 KB Output is correct
93 Correct 206 ms 18752 KB Output is correct
94 Correct 200 ms 18688 KB Output is correct
95 Correct 211 ms 18612 KB Output is correct
96 Correct 205 ms 18716 KB Output is correct
97 Correct 195 ms 18316 KB Output is correct
98 Correct 193 ms 18712 KB Output is correct
99 Correct 160 ms 17720 KB Output is correct
100 Correct 206 ms 18692 KB Output is correct
101 Correct 237 ms 19116 KB Output is correct
102 Correct 154 ms 17468 KB Output is correct
103 Correct 222 ms 19508 KB Output is correct
104 Correct 220 ms 20020 KB Output is correct
105 Correct 181 ms 20364 KB Output is correct
106 Correct 142 ms 17440 KB Output is correct