Submission #373259

# Submission time Handle Problem Language Result Execution time Memory
373259 2021-03-03T23:50:06 Z MilosMilutinovic Job Scheduling (IOI19_job) C++14
100 / 100
239 ms 56668 KB
#include "job.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back

const int mxN=2e5;
int n;
vector<int> adj[mxN];
vector<ll> p(mxN), u(mxN), d(mxN);
bool was[mxN];
ll ans=0;

struct cmp{
	bool operator()(int x, int y) {
		return (ll)d[x]*(ll)u[y]>(ll)d[y]*(ll)u[x];
	}
};

priority_queue<int, vector<int>, cmp> q[mxN];

void merge(int x, int y) {
	d[x]+=d[y];
	u[x]+=u[y];	
}

void dfs(int x) {
	assert(x>=0&&x<n);
	for(int v:adj[x])
		dfs(v), q[x].push(v);
	while(!q[x].empty()) {
		int y=q[x].top();
		if((ll)d[y]*(ll)u[x]>(ll)d[x]*(ll)u[y])
			break;
		was[y]=true;
		q[x].pop();
		ans-=d[y]*u[x];
		merge(x, y);
		if((int)q[x].size()<(int)q[y].size())
			swap(q[x], q[y]);
		while(!q[y].empty())
			q[x].push(q[y].top()), q[y].pop();
	}	
}

ll scheduling_cost(vector<int> p1, vector<int> u1, vector<int> d1) {
	n = (int) p1.size();
	for(int i=0; i<n; ++i)
		p[i]=(ll)p1[i], u[i]=(ll)u1[i], d[i]=(ll)d1[i];
	for(int i=1; i<n; ++i) 
		adj[p[i]].pb(i);
	dfs(0);
	vector<int> j;
	for(int i=0; i<n; ++i)
		if(!was[i])
			j.pb(i);
	sort(j.rbegin(), j.rend(), [&](int x, int y) {
		return (ll)d[x]*u[y]>(ll)d[y]*u[x];
	});
	ll t=0LL;
	for(int i:j)
		t+=d[i], ans+=(ll)u[i]*t;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15980 KB Output is correct
2 Correct 10 ms 15980 KB Output is correct
3 Correct 10 ms 16000 KB Output is correct
4 Correct 11 ms 16108 KB Output is correct
5 Correct 39 ms 25836 KB Output is correct
6 Correct 66 ms 35564 KB Output is correct
7 Correct 96 ms 45548 KB Output is correct
8 Correct 123 ms 55404 KB Output is correct
9 Correct 130 ms 55404 KB Output is correct
10 Correct 124 ms 55404 KB Output is correct
11 Correct 10 ms 15980 KB Output is correct
12 Correct 121 ms 55404 KB Output is correct
13 Correct 123 ms 55404 KB Output is correct
14 Correct 127 ms 55404 KB Output is correct
15 Correct 119 ms 55404 KB Output is correct
16 Correct 122 ms 55404 KB Output is correct
17 Correct 123 ms 55404 KB Output is correct
18 Correct 123 ms 55404 KB Output is correct
19 Correct 122 ms 55408 KB Output is correct
20 Correct 153 ms 56668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15980 KB Output is correct
2 Correct 11 ms 15980 KB Output is correct
3 Correct 11 ms 15980 KB Output is correct
4 Correct 121 ms 24032 KB Output is correct
5 Correct 113 ms 24032 KB Output is correct
6 Correct 115 ms 24032 KB Output is correct
7 Correct 143 ms 24032 KB Output is correct
8 Correct 110 ms 23904 KB Output is correct
9 Correct 111 ms 23976 KB Output is correct
10 Correct 113 ms 24032 KB Output is correct
11 Correct 114 ms 23904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15980 KB Output is correct
2 Correct 11 ms 15980 KB Output is correct
3 Correct 12 ms 15980 KB Output is correct
4 Correct 12 ms 15980 KB Output is correct
5 Correct 18 ms 16640 KB Output is correct
6 Correct 119 ms 24032 KB Output is correct
7 Correct 122 ms 24032 KB Output is correct
8 Correct 119 ms 24084 KB Output is correct
9 Correct 119 ms 24032 KB Output is correct
10 Correct 10 ms 15980 KB Output is correct
11 Correct 11 ms 15980 KB Output is correct
12 Correct 15 ms 16364 KB Output is correct
13 Correct 15 ms 16364 KB Output is correct
14 Correct 120 ms 23992 KB Output is correct
15 Correct 119 ms 24032 KB Output is correct
16 Correct 121 ms 24032 KB Output is correct
17 Correct 119 ms 24032 KB Output is correct
18 Correct 128 ms 23752 KB Output is correct
19 Correct 125 ms 24032 KB Output is correct
20 Correct 120 ms 24032 KB Output is correct
21 Correct 118 ms 23904 KB Output is correct
22 Correct 120 ms 24032 KB Output is correct
23 Correct 122 ms 24032 KB Output is correct
24 Correct 135 ms 24032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15980 KB Output is correct
2 Correct 119 ms 42732 KB Output is correct
3 Correct 121 ms 45932 KB Output is correct
4 Correct 133 ms 45932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16128 KB Output is correct
2 Correct 11 ms 15980 KB Output is correct
3 Correct 11 ms 15980 KB Output is correct
4 Correct 11 ms 15980 KB Output is correct
5 Correct 10 ms 15980 KB Output is correct
6 Correct 11 ms 15980 KB Output is correct
7 Correct 10 ms 15980 KB Output is correct
8 Correct 10 ms 15980 KB Output is correct
9 Correct 11 ms 15980 KB Output is correct
10 Correct 11 ms 15980 KB Output is correct
11 Correct 10 ms 15980 KB Output is correct
12 Correct 11 ms 15980 KB Output is correct
13 Correct 11 ms 16128 KB Output is correct
14 Correct 12 ms 15980 KB Output is correct
15 Correct 11 ms 15980 KB Output is correct
16 Correct 11 ms 15980 KB Output is correct
17 Correct 10 ms 15980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15980 KB Output is correct
2 Correct 10 ms 15980 KB Output is correct
3 Correct 10 ms 16000 KB Output is correct
4 Correct 11 ms 16108 KB Output is correct
5 Correct 39 ms 25836 KB Output is correct
6 Correct 66 ms 35564 KB Output is correct
7 Correct 96 ms 45548 KB Output is correct
8 Correct 123 ms 55404 KB Output is correct
9 Correct 130 ms 55404 KB Output is correct
10 Correct 124 ms 55404 KB Output is correct
11 Correct 10 ms 15980 KB Output is correct
12 Correct 121 ms 55404 KB Output is correct
13 Correct 123 ms 55404 KB Output is correct
14 Correct 127 ms 55404 KB Output is correct
15 Correct 119 ms 55404 KB Output is correct
16 Correct 122 ms 55404 KB Output is correct
17 Correct 123 ms 55404 KB Output is correct
18 Correct 123 ms 55404 KB Output is correct
19 Correct 122 ms 55408 KB Output is correct
20 Correct 153 ms 56668 KB Output is correct
21 Correct 10 ms 15980 KB Output is correct
22 Correct 11 ms 15980 KB Output is correct
23 Correct 11 ms 15980 KB Output is correct
24 Correct 121 ms 24032 KB Output is correct
25 Correct 113 ms 24032 KB Output is correct
26 Correct 115 ms 24032 KB Output is correct
27 Correct 143 ms 24032 KB Output is correct
28 Correct 110 ms 23904 KB Output is correct
29 Correct 111 ms 23976 KB Output is correct
30 Correct 113 ms 24032 KB Output is correct
31 Correct 114 ms 23904 KB Output is correct
32 Correct 10 ms 15980 KB Output is correct
33 Correct 11 ms 15980 KB Output is correct
34 Correct 12 ms 15980 KB Output is correct
35 Correct 12 ms 15980 KB Output is correct
36 Correct 18 ms 16640 KB Output is correct
37 Correct 119 ms 24032 KB Output is correct
38 Correct 122 ms 24032 KB Output is correct
39 Correct 119 ms 24084 KB Output is correct
40 Correct 119 ms 24032 KB Output is correct
41 Correct 10 ms 15980 KB Output is correct
42 Correct 11 ms 15980 KB Output is correct
43 Correct 15 ms 16364 KB Output is correct
44 Correct 15 ms 16364 KB Output is correct
45 Correct 120 ms 23992 KB Output is correct
46 Correct 119 ms 24032 KB Output is correct
47 Correct 121 ms 24032 KB Output is correct
48 Correct 119 ms 24032 KB Output is correct
49 Correct 128 ms 23752 KB Output is correct
50 Correct 125 ms 24032 KB Output is correct
51 Correct 120 ms 24032 KB Output is correct
52 Correct 118 ms 23904 KB Output is correct
53 Correct 120 ms 24032 KB Output is correct
54 Correct 122 ms 24032 KB Output is correct
55 Correct 135 ms 24032 KB Output is correct
56 Correct 11 ms 15980 KB Output is correct
57 Correct 119 ms 42732 KB Output is correct
58 Correct 121 ms 45932 KB Output is correct
59 Correct 133 ms 45932 KB Output is correct
60 Correct 11 ms 16128 KB Output is correct
61 Correct 11 ms 15980 KB Output is correct
62 Correct 11 ms 15980 KB Output is correct
63 Correct 11 ms 15980 KB Output is correct
64 Correct 10 ms 15980 KB Output is correct
65 Correct 11 ms 15980 KB Output is correct
66 Correct 10 ms 15980 KB Output is correct
67 Correct 10 ms 15980 KB Output is correct
68 Correct 11 ms 15980 KB Output is correct
69 Correct 11 ms 15980 KB Output is correct
70 Correct 10 ms 15980 KB Output is correct
71 Correct 11 ms 15980 KB Output is correct
72 Correct 11 ms 16128 KB Output is correct
73 Correct 12 ms 15980 KB Output is correct
74 Correct 11 ms 15980 KB Output is correct
75 Correct 11 ms 15980 KB Output is correct
76 Correct 10 ms 15980 KB Output is correct
77 Correct 11 ms 15980 KB Output is correct
78 Correct 11 ms 15980 KB Output is correct
79 Correct 11 ms 15980 KB Output is correct
80 Correct 11 ms 15980 KB Output is correct
81 Correct 10 ms 15980 KB Output is correct
82 Correct 10 ms 15980 KB Output is correct
83 Correct 10 ms 15980 KB Output is correct
84 Correct 12 ms 16000 KB Output is correct
85 Correct 10 ms 15980 KB Output is correct
86 Correct 11 ms 15980 KB Output is correct
87 Correct 10 ms 15980 KB Output is correct
88 Correct 14 ms 16364 KB Output is correct
89 Correct 18 ms 16620 KB Output is correct
90 Correct 17 ms 16876 KB Output is correct
91 Correct 50 ms 19820 KB Output is correct
92 Correct 96 ms 23720 KB Output is correct
93 Correct 195 ms 31344 KB Output is correct
94 Correct 201 ms 31300 KB Output is correct
95 Correct 204 ms 31340 KB Output is correct
96 Correct 239 ms 31340 KB Output is correct
97 Correct 184 ms 29672 KB Output is correct
98 Correct 204 ms 32748 KB Output is correct
99 Correct 171 ms 29284 KB Output is correct
100 Correct 197 ms 31344 KB Output is correct
101 Correct 190 ms 33000 KB Output is correct
102 Correct 214 ms 31496 KB Output is correct
103 Correct 194 ms 30956 KB Output is correct
104 Correct 198 ms 32492 KB Output is correct
105 Correct 148 ms 33132 KB Output is correct
106 Correct 140 ms 26852 KB Output is correct