Submission #331293

# Submission time Handle Problem Language Result Execution time Memory
331293 2020-11-28T00:59:29 Z ttnhuy313 Job Scheduling (IOI19_job) C++14
100 / 100
252 ms 20968 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
typedef pair <int, int> ii;

const int N = 2e5 + 5;
int n, dp[N], cost[N], d[N], lab[N], res;

struct obj {
	int sum_d, sum_cost;
	bool operator < (const obj other) const {
		return sum_d * other.sum_cost > other.sum_d * sum_cost;
	}
	bool operator != (const obj other) const {
		return ii(sum_d, sum_cost) != ii(other.sum_d, other.sum_cost);
	}
} a[N];

int root(int x) {
	if (lab[x] == -1) return x;
	else return lab[x] = root(lab[x]);
}

int scheduling_cost(vector <int32_t> p, vector <int32_t> c, vector <int32_t> time) {
	memset(lab, -1, sizeof lab);	
	n = p.size();
	priority_queue <pair <obj, int>> pq;
	while (!pq.empty()) pq.pop();
	for (int i = 0; i < n; ++i) {
		cost[i] = c[i];
		d[i] = time[i];
		a[i] = {d[i], cost[i]};
		res += d[i] * cost[i];
		pq.push({a[i], i});
	}
	while (!pq.empty()) {
		obj cur = pq.top().first; int u = pq.top().second;
		pq.pop();
		if (cur != a[u] || u == 0) continue;
		int v = root(p[u]);
		res += a[v].sum_d * a[u].sum_cost;
		a[v].sum_d += a[u].sum_d; a[v].sum_cost += a[u].sum_cost;
		lab[u] = v;
		pq.push({a[v], v});
	}
	return res;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 2 ms 1900 KB Output is correct
4 Correct 2 ms 2028 KB Output is correct
5 Correct 46 ms 6776 KB Output is correct
6 Correct 95 ms 11360 KB Output is correct
7 Correct 170 ms 18144 KB Output is correct
8 Correct 233 ms 20968 KB Output is correct
9 Correct 229 ms 20944 KB Output is correct
10 Correct 229 ms 20948 KB Output is correct
11 Correct 2 ms 1900 KB Output is correct
12 Correct 252 ms 20828 KB Output is correct
13 Correct 183 ms 20956 KB Output is correct
14 Correct 200 ms 20828 KB Output is correct
15 Correct 150 ms 20924 KB Output is correct
16 Correct 173 ms 20828 KB Output is correct
17 Correct 225 ms 20884 KB Output is correct
18 Correct 232 ms 20828 KB Output is correct
19 Correct 139 ms 20848 KB Output is correct
20 Correct 139 ms 20956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1900 KB Output is correct
2 Correct 2 ms 1900 KB Output is correct
3 Correct 2 ms 2028 KB Output is correct
4 Correct 184 ms 19548 KB Output is correct
5 Correct 185 ms 19548 KB Output is correct
6 Correct 186 ms 19420 KB Output is correct
7 Correct 188 ms 19420 KB Output is correct
8 Correct 179 ms 19420 KB Output is correct
9 Correct 181 ms 19420 KB Output is correct
10 Correct 186 ms 19420 KB Output is correct
11 Correct 185 ms 19420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1900 KB Output is correct
4 Correct 2 ms 2028 KB Output is correct
5 Correct 10 ms 2992 KB Output is correct
6 Correct 176 ms 19964 KB Output is correct
7 Correct 177 ms 19932 KB Output is correct
8 Correct 184 ms 19932 KB Output is correct
9 Correct 183 ms 19932 KB Output is correct
10 Correct 1 ms 1900 KB Output is correct
11 Correct 2 ms 2028 KB Output is correct
12 Correct 8 ms 2992 KB Output is correct
13 Correct 8 ms 2992 KB Output is correct
14 Correct 177 ms 19980 KB Output is correct
15 Correct 192 ms 19980 KB Output is correct
16 Correct 175 ms 19932 KB Output is correct
17 Correct 172 ms 19932 KB Output is correct
18 Correct 176 ms 19932 KB Output is correct
19 Correct 174 ms 19932 KB Output is correct
20 Correct 179 ms 19932 KB Output is correct
21 Correct 179 ms 19932 KB Output is correct
22 Correct 177 ms 19932 KB Output is correct
23 Correct 174 ms 20060 KB Output is correct
24 Correct 178 ms 20060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1900 KB Output is correct
2 Correct 240 ms 20908 KB Output is correct
3 Correct 234 ms 20948 KB Output is correct
4 Correct 229 ms 20948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1900 KB Output is correct
4 Correct 1 ms 1900 KB Output is correct
5 Correct 2 ms 1900 KB Output is correct
6 Correct 2 ms 1900 KB Output is correct
7 Correct 2 ms 1900 KB Output is correct
8 Correct 2 ms 2028 KB Output is correct
9 Correct 2 ms 1900 KB Output is correct
10 Correct 2 ms 1900 KB Output is correct
11 Correct 2 ms 1900 KB Output is correct
12 Correct 2 ms 1900 KB Output is correct
13 Correct 2 ms 1900 KB Output is correct
14 Correct 1 ms 1900 KB Output is correct
15 Correct 2 ms 1900 KB Output is correct
16 Correct 2 ms 1900 KB Output is correct
17 Correct 2 ms 1900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1900 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 2 ms 1900 KB Output is correct
4 Correct 2 ms 2028 KB Output is correct
5 Correct 46 ms 6776 KB Output is correct
6 Correct 95 ms 11360 KB Output is correct
7 Correct 170 ms 18144 KB Output is correct
8 Correct 233 ms 20968 KB Output is correct
9 Correct 229 ms 20944 KB Output is correct
10 Correct 229 ms 20948 KB Output is correct
11 Correct 2 ms 1900 KB Output is correct
12 Correct 252 ms 20828 KB Output is correct
13 Correct 183 ms 20956 KB Output is correct
14 Correct 200 ms 20828 KB Output is correct
15 Correct 150 ms 20924 KB Output is correct
16 Correct 173 ms 20828 KB Output is correct
17 Correct 225 ms 20884 KB Output is correct
18 Correct 232 ms 20828 KB Output is correct
19 Correct 139 ms 20848 KB Output is correct
20 Correct 139 ms 20956 KB Output is correct
21 Correct 1 ms 1900 KB Output is correct
22 Correct 2 ms 1900 KB Output is correct
23 Correct 2 ms 2028 KB Output is correct
24 Correct 184 ms 19548 KB Output is correct
25 Correct 185 ms 19548 KB Output is correct
26 Correct 186 ms 19420 KB Output is correct
27 Correct 188 ms 19420 KB Output is correct
28 Correct 179 ms 19420 KB Output is correct
29 Correct 181 ms 19420 KB Output is correct
30 Correct 186 ms 19420 KB Output is correct
31 Correct 185 ms 19420 KB Output is correct
32 Correct 2 ms 1900 KB Output is correct
33 Correct 1 ms 1900 KB Output is correct
34 Correct 1 ms 1900 KB Output is correct
35 Correct 2 ms 2028 KB Output is correct
36 Correct 10 ms 2992 KB Output is correct
37 Correct 176 ms 19964 KB Output is correct
38 Correct 177 ms 19932 KB Output is correct
39 Correct 184 ms 19932 KB Output is correct
40 Correct 183 ms 19932 KB Output is correct
41 Correct 1 ms 1900 KB Output is correct
42 Correct 2 ms 2028 KB Output is correct
43 Correct 8 ms 2992 KB Output is correct
44 Correct 8 ms 2992 KB Output is correct
45 Correct 177 ms 19980 KB Output is correct
46 Correct 192 ms 19980 KB Output is correct
47 Correct 175 ms 19932 KB Output is correct
48 Correct 172 ms 19932 KB Output is correct
49 Correct 176 ms 19932 KB Output is correct
50 Correct 174 ms 19932 KB Output is correct
51 Correct 179 ms 19932 KB Output is correct
52 Correct 179 ms 19932 KB Output is correct
53 Correct 177 ms 19932 KB Output is correct
54 Correct 174 ms 20060 KB Output is correct
55 Correct 178 ms 20060 KB Output is correct
56 Correct 1 ms 1900 KB Output is correct
57 Correct 240 ms 20908 KB Output is correct
58 Correct 234 ms 20948 KB Output is correct
59 Correct 229 ms 20948 KB Output is correct
60 Correct 2 ms 1900 KB Output is correct
61 Correct 1 ms 1900 KB Output is correct
62 Correct 1 ms 1900 KB Output is correct
63 Correct 1 ms 1900 KB Output is correct
64 Correct 2 ms 1900 KB Output is correct
65 Correct 2 ms 1900 KB Output is correct
66 Correct 2 ms 1900 KB Output is correct
67 Correct 2 ms 2028 KB Output is correct
68 Correct 2 ms 1900 KB Output is correct
69 Correct 2 ms 1900 KB Output is correct
70 Correct 2 ms 1900 KB Output is correct
71 Correct 2 ms 1900 KB Output is correct
72 Correct 2 ms 1900 KB Output is correct
73 Correct 1 ms 1900 KB Output is correct
74 Correct 2 ms 1900 KB Output is correct
75 Correct 2 ms 1900 KB Output is correct
76 Correct 2 ms 1900 KB Output is correct
77 Correct 1 ms 1900 KB Output is correct
78 Correct 2 ms 1900 KB Output is correct
79 Correct 1 ms 1900 KB Output is correct
80 Correct 1 ms 1900 KB Output is correct
81 Correct 1 ms 1900 KB Output is correct
82 Correct 1 ms 1900 KB Output is correct
83 Correct 1 ms 1900 KB Output is correct
84 Correct 1 ms 1900 KB Output is correct
85 Correct 1 ms 1900 KB Output is correct
86 Correct 2 ms 1900 KB Output is correct
87 Correct 2 ms 1900 KB Output is correct
88 Correct 5 ms 2540 KB Output is correct
89 Correct 7 ms 2736 KB Output is correct
90 Correct 9 ms 2992 KB Output is correct
91 Correct 43 ms 6756 KB Output is correct
92 Correct 93 ms 11360 KB Output is correct
93 Correct 245 ms 20720 KB Output is correct
94 Correct 225 ms 20956 KB Output is correct
95 Correct 232 ms 20828 KB Output is correct
96 Correct 236 ms 20828 KB Output is correct
97 Correct 210 ms 20828 KB Output is correct
98 Correct 218 ms 20828 KB Output is correct
99 Correct 194 ms 20700 KB Output is correct
100 Correct 235 ms 20956 KB Output is correct
101 Correct 252 ms 20828 KB Output is correct
102 Correct 200 ms 20828 KB Output is correct
103 Correct 221 ms 20828 KB Output is correct
104 Correct 235 ms 20828 KB Output is correct
105 Correct 169 ms 20956 KB Output is correct
106 Correct 190 ms 20464 KB Output is correct