Submission #316761

# Submission time Handle Problem Language Result Execution time Memory
316761 2020-10-27T22:35:12 Z MetB Job Scheduling (IOI19_job) C++14
100 / 100
256 ms 18688 KB
#include "job.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
 
#define N 2000001
 
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
 
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;
 
int merged[N], dsu[N], n, dl[N];
ll ans;
 
struct rat {
	ll u, d;
 
	rat (ll u, ll d) : u (u), d (d) {}
	rat () {}
 
	bool operator < (const rat& b) const {
		return b.u * d > u * b.d;
	}
 
	bool operator != (const rat& b) const {
		return tie (u, d) != tie (b.u, b.d);
	}
} a[N];
 
int find (int x) {
	if (dsu[x] == x) return x;
	return dsu[x] = find (dsu[x]);
}
 
void unite (int a, int b) {
	a = find (a), b = find (b);
	if (a == b) return;
	dsu[b] = a;
	merged[b] = 1;
}
 
ll scheduling_cost (vector <int> p, vector <int> u, vector <int> d) {
	int n = p.size ();
	
	p.resize (n);
	u.resize (n);
	d.resize (n);
	
	priority_queue < pair <rat, int> > q;
 
	for (int i = 0; i < n; i++) {
		a[i] = {u[i], d[i]};
		dsu[i] = i;
		q.push ({a[i], i});
	}
 
	ll t = 0;
 
	while (!q.empty ()) {
		ll x = q.top ().second;
		rat cost = q.top ().first;
		q.pop ();
		if (a[x] != cost || merged[x] || dl[x]) continue;
 
		if (p[x] == -1 || dl[find (p[x])]) {
			ans += (d[x] + t) * u[x];
			dl[x] = 1;
			t += d[x];
			continue;
		}
		int desc = find (p[x]);
		ans -= (ll) d[x] * u[desc];
		u[desc] += u[x];
		d[desc] += d[x];
		a[desc] = {u[desc], d[desc]};
		unite (desc, x);
 
		q.push ({a[desc], desc});
	}
 
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 45 ms 4076 KB Output is correct
6 Correct 106 ms 7500 KB Output is correct
7 Correct 171 ms 12776 KB Output is correct
8 Correct 246 ms 14568 KB Output is correct
9 Correct 253 ms 14860 KB Output is correct
10 Correct 247 ms 14564 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 251 ms 14684 KB Output is correct
13 Correct 185 ms 14564 KB Output is correct
14 Correct 206 ms 15324 KB Output is correct
15 Correct 158 ms 14600 KB Output is correct
16 Correct 183 ms 15324 KB Output is correct
17 Correct 245 ms 14564 KB Output is correct
18 Correct 249 ms 14624 KB Output is correct
19 Correct 145 ms 14564 KB Output is correct
20 Correct 127 ms 15324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 155 ms 16744 KB Output is correct
5 Correct 148 ms 16996 KB Output is correct
6 Correct 149 ms 16488 KB Output is correct
7 Correct 150 ms 16996 KB Output is correct
8 Correct 149 ms 16264 KB Output is correct
9 Correct 152 ms 16996 KB Output is correct
10 Correct 156 ms 17124 KB Output is correct
11 Correct 149 ms 16356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 8 ms 1348 KB Output is correct
6 Correct 157 ms 16868 KB Output is correct
7 Correct 152 ms 16868 KB Output is correct
8 Correct 153 ms 16996 KB Output is correct
9 Correct 153 ms 16868 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 6 ms 1348 KB Output is correct
13 Correct 7 ms 1348 KB Output is correct
14 Correct 151 ms 16996 KB Output is correct
15 Correct 155 ms 16612 KB Output is correct
16 Correct 152 ms 16996 KB Output is correct
17 Correct 150 ms 16996 KB Output is correct
18 Correct 148 ms 16228 KB Output is correct
19 Correct 156 ms 16868 KB Output is correct
20 Correct 152 ms 16868 KB Output is correct
21 Correct 149 ms 16356 KB Output is correct
22 Correct 152 ms 16620 KB Output is correct
23 Correct 153 ms 16996 KB Output is correct
24 Correct 151 ms 16228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 248 ms 16384 KB Output is correct
3 Correct 251 ms 17780 KB Output is correct
4 Correct 246 ms 17884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 45 ms 4076 KB Output is correct
6 Correct 106 ms 7500 KB Output is correct
7 Correct 171 ms 12776 KB Output is correct
8 Correct 246 ms 14568 KB Output is correct
9 Correct 253 ms 14860 KB Output is correct
10 Correct 247 ms 14564 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 251 ms 14684 KB Output is correct
13 Correct 185 ms 14564 KB Output is correct
14 Correct 206 ms 15324 KB Output is correct
15 Correct 158 ms 14600 KB Output is correct
16 Correct 183 ms 15324 KB Output is correct
17 Correct 245 ms 14564 KB Output is correct
18 Correct 249 ms 14624 KB Output is correct
19 Correct 145 ms 14564 KB Output is correct
20 Correct 127 ms 15324 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 155 ms 16744 KB Output is correct
25 Correct 148 ms 16996 KB Output is correct
26 Correct 149 ms 16488 KB Output is correct
27 Correct 150 ms 16996 KB Output is correct
28 Correct 149 ms 16264 KB Output is correct
29 Correct 152 ms 16996 KB Output is correct
30 Correct 156 ms 17124 KB Output is correct
31 Correct 149 ms 16356 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 8 ms 1348 KB Output is correct
37 Correct 157 ms 16868 KB Output is correct
38 Correct 152 ms 16868 KB Output is correct
39 Correct 153 ms 16996 KB Output is correct
40 Correct 153 ms 16868 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 512 KB Output is correct
43 Correct 6 ms 1348 KB Output is correct
44 Correct 7 ms 1348 KB Output is correct
45 Correct 151 ms 16996 KB Output is correct
46 Correct 155 ms 16612 KB Output is correct
47 Correct 152 ms 16996 KB Output is correct
48 Correct 150 ms 16996 KB Output is correct
49 Correct 148 ms 16228 KB Output is correct
50 Correct 156 ms 16868 KB Output is correct
51 Correct 152 ms 16868 KB Output is correct
52 Correct 149 ms 16356 KB Output is correct
53 Correct 152 ms 16620 KB Output is correct
54 Correct 153 ms 16996 KB Output is correct
55 Correct 151 ms 16228 KB Output is correct
56 Correct 0 ms 384 KB Output is correct
57 Correct 248 ms 16384 KB Output is correct
58 Correct 251 ms 17780 KB Output is correct
59 Correct 246 ms 17884 KB Output is correct
60 Correct 0 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 0 ms 384 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 1 ms 384 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 1 ms 384 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 1 ms 384 KB Output is correct
81 Correct 0 ms 384 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 0 ms 384 KB Output is correct
86 Correct 1 ms 384 KB Output is correct
87 Correct 1 ms 384 KB Output is correct
88 Correct 4 ms 960 KB Output is correct
89 Correct 6 ms 1220 KB Output is correct
90 Correct 8 ms 1408 KB Output is correct
91 Correct 42 ms 4980 KB Output is correct
92 Correct 97 ms 9448 KB Output is correct
93 Correct 231 ms 18396 KB Output is correct
94 Correct 236 ms 18396 KB Output is correct
95 Correct 236 ms 18396 KB Output is correct
96 Correct 228 ms 18400 KB Output is correct
97 Correct 213 ms 18400 KB Output is correct
98 Correct 216 ms 18524 KB Output is correct
99 Correct 186 ms 18404 KB Output is correct
100 Correct 226 ms 18396 KB Output is correct
101 Correct 256 ms 18688 KB Output is correct
102 Correct 167 ms 17764 KB Output is correct
103 Correct 239 ms 18400 KB Output is correct
104 Correct 247 ms 18564 KB Output is correct
105 Correct 175 ms 18396 KB Output is correct
106 Correct 162 ms 17380 KB Output is correct