Submission #143413

# Submission time Handle Problem Language Result Execution time Memory
143413 2019-08-14T00:24:04 Z model_code Job Scheduling (IOI19_job) C++17
100 / 100
505 ms 90172 KB
// model_solution/job-mruxim.cpp

// ... ... .. ....!
// ... ....... .... ...!

#include<bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0, i##__n = (int)(n); i < i##__n; ++i)
#define fer(i, a, b) for(int i = (int)(a), i##__b = (int)(b); i < i##__b; ++i)
#define rof(i, b, a) for(int i = (int)(b), i##__a = (int)(a); i-- > i##__a; )
#define sz(x) (int((x).size()))
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
//#define endl '\n'

template<class P, class Q> inline void smin(P &a, Q b) { if (b < a) a = b; }
template<class P, class Q> inline void smax(P &a, Q b) { if (a < b) a = b; }

typedef long long ll;
typedef pair<int, int> pii;

////////////////////////////////////////////////////////////////////////////////

const int maxn = 200000 + 100;

int par[maxn];

struct Job {
	ll urg, dur;
	bool operator<(Job j) const {
//		return urg * j.dur > j.urg * dur;
		return urg / (double)dur > j.urg / (double)j.dur;
	}
} jobs[maxn];

vector<int> child[maxn];
multiset<Job> path[maxn];

ll ans;

void dfs(int u) {
	int big = -1;

	for(int v: child[u]) {
		dfs(v);
		if(big == -1 || sz(path[v]) > sz(path[big]))
			big = v;
	}
	
	if(big != -1)
		path[u] = move(path[big]);

	for(int v: child[u])
		if(v != big)
			for(Job j: path[v])
				path[u].insert(j);

	Job cur = jobs[u];
	while(!path[u].empty() && *path[u].begin() < cur)
		ans += cur.dur * path[u].begin()->urg,
		cur.urg += path[u].begin()->urg,
		cur.dur += path[u].begin()->dur,
		path[u].erase(path[u].begin());
	path[u].insert(cur);
}

long long scheduling_cost(vector<int> P, vector<int> U, vector<int> D) {
	int n = sz(U);
	rep(i, n) jobs[i].urg = U[i], jobs[i].dur = D[i];

	int root = -1;
	rep(i, n) {
		par[i] = P[i];
		if(par[i] == -1)
			root = i;
		else
			child[par[i]].pb(i);
	}

	dfs(root);

	ll c_time = 0;
	for(Job j: path[root])
		ans += c_time * j.urg,
		c_time += j.dur;

	rep(i, n) ans += U[i] * D[i];

	return ans;
}

# Verdict Execution time Memory Grader output
1 Correct 15 ms 14456 KB Output is correct
2 Correct 17 ms 14456 KB Output is correct
3 Correct 14 ms 14456 KB Output is correct
4 Correct 18 ms 14584 KB Output is correct
5 Correct 49 ms 24440 KB Output is correct
6 Correct 84 ms 34428 KB Output is correct
7 Correct 118 ms 44408 KB Output is correct
8 Correct 152 ms 54324 KB Output is correct
9 Correct 152 ms 54432 KB Output is correct
10 Correct 151 ms 54392 KB Output is correct
11 Correct 14 ms 14456 KB Output is correct
12 Correct 153 ms 54364 KB Output is correct
13 Correct 145 ms 54392 KB Output is correct
14 Correct 157 ms 54364 KB Output is correct
15 Correct 145 ms 54268 KB Output is correct
16 Correct 164 ms 54584 KB Output is correct
17 Correct 152 ms 54284 KB Output is correct
18 Correct 151 ms 54312 KB Output is correct
19 Correct 144 ms 54480 KB Output is correct
20 Correct 191 ms 62980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14456 KB Output is correct
4 Correct 285 ms 48928 KB Output is correct
5 Correct 275 ms 48940 KB Output is correct
6 Correct 275 ms 48928 KB Output is correct
7 Correct 272 ms 48876 KB Output is correct
8 Correct 277 ms 48876 KB Output is correct
9 Correct 276 ms 48876 KB Output is correct
10 Correct 271 ms 48876 KB Output is correct
11 Correct 270 ms 48876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14456 KB Output is correct
4 Correct 15 ms 14584 KB Output is correct
5 Correct 25 ms 16092 KB Output is correct
6 Correct 279 ms 49064 KB Output is correct
7 Correct 285 ms 49064 KB Output is correct
8 Correct 288 ms 48884 KB Output is correct
9 Correct 289 ms 48868 KB Output is correct
10 Correct 14 ms 14456 KB Output is correct
11 Correct 15 ms 14712 KB Output is correct
12 Correct 22 ms 15864 KB Output is correct
13 Correct 24 ms 16220 KB Output is correct
14 Correct 283 ms 48876 KB Output is correct
15 Correct 284 ms 48876 KB Output is correct
16 Correct 279 ms 48876 KB Output is correct
17 Correct 284 ms 48880 KB Output is correct
18 Correct 306 ms 49004 KB Output is correct
19 Correct 285 ms 48876 KB Output is correct
20 Correct 284 ms 48876 KB Output is correct
21 Correct 285 ms 48876 KB Output is correct
22 Correct 276 ms 48896 KB Output is correct
23 Correct 287 ms 48960 KB Output is correct
24 Correct 274 ms 49004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 146 ms 41848 KB Output is correct
3 Correct 146 ms 41848 KB Output is correct
4 Correct 146 ms 41848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14456 KB Output is correct
4 Correct 14 ms 14456 KB Output is correct
5 Correct 14 ms 14456 KB Output is correct
6 Correct 17 ms 14460 KB Output is correct
7 Correct 14 ms 14456 KB Output is correct
8 Correct 14 ms 14456 KB Output is correct
9 Correct 17 ms 14392 KB Output is correct
10 Correct 14 ms 14456 KB Output is correct
11 Correct 15 ms 14584 KB Output is correct
12 Correct 14 ms 14456 KB Output is correct
13 Correct 14 ms 14584 KB Output is correct
14 Correct 15 ms 14428 KB Output is correct
15 Correct 14 ms 14456 KB Output is correct
16 Correct 14 ms 14456 KB Output is correct
17 Correct 14 ms 14456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 14456 KB Output is correct
2 Correct 17 ms 14456 KB Output is correct
3 Correct 14 ms 14456 KB Output is correct
4 Correct 18 ms 14584 KB Output is correct
5 Correct 49 ms 24440 KB Output is correct
6 Correct 84 ms 34428 KB Output is correct
7 Correct 118 ms 44408 KB Output is correct
8 Correct 152 ms 54324 KB Output is correct
9 Correct 152 ms 54432 KB Output is correct
10 Correct 151 ms 54392 KB Output is correct
11 Correct 14 ms 14456 KB Output is correct
12 Correct 153 ms 54364 KB Output is correct
13 Correct 145 ms 54392 KB Output is correct
14 Correct 157 ms 54364 KB Output is correct
15 Correct 145 ms 54268 KB Output is correct
16 Correct 164 ms 54584 KB Output is correct
17 Correct 152 ms 54284 KB Output is correct
18 Correct 151 ms 54312 KB Output is correct
19 Correct 144 ms 54480 KB Output is correct
20 Correct 191 ms 62980 KB Output is correct
21 Correct 14 ms 14456 KB Output is correct
22 Correct 14 ms 14456 KB Output is correct
23 Correct 14 ms 14456 KB Output is correct
24 Correct 285 ms 48928 KB Output is correct
25 Correct 275 ms 48940 KB Output is correct
26 Correct 275 ms 48928 KB Output is correct
27 Correct 272 ms 48876 KB Output is correct
28 Correct 277 ms 48876 KB Output is correct
29 Correct 276 ms 48876 KB Output is correct
30 Correct 271 ms 48876 KB Output is correct
31 Correct 270 ms 48876 KB Output is correct
32 Correct 14 ms 14456 KB Output is correct
33 Correct 14 ms 14456 KB Output is correct
34 Correct 14 ms 14456 KB Output is correct
35 Correct 15 ms 14584 KB Output is correct
36 Correct 25 ms 16092 KB Output is correct
37 Correct 279 ms 49064 KB Output is correct
38 Correct 285 ms 49064 KB Output is correct
39 Correct 288 ms 48884 KB Output is correct
40 Correct 289 ms 48868 KB Output is correct
41 Correct 14 ms 14456 KB Output is correct
42 Correct 15 ms 14712 KB Output is correct
43 Correct 22 ms 15864 KB Output is correct
44 Correct 24 ms 16220 KB Output is correct
45 Correct 283 ms 48876 KB Output is correct
46 Correct 284 ms 48876 KB Output is correct
47 Correct 279 ms 48876 KB Output is correct
48 Correct 284 ms 48880 KB Output is correct
49 Correct 306 ms 49004 KB Output is correct
50 Correct 285 ms 48876 KB Output is correct
51 Correct 284 ms 48876 KB Output is correct
52 Correct 285 ms 48876 KB Output is correct
53 Correct 276 ms 48896 KB Output is correct
54 Correct 287 ms 48960 KB Output is correct
55 Correct 274 ms 49004 KB Output is correct
56 Correct 14 ms 14456 KB Output is correct
57 Correct 146 ms 41848 KB Output is correct
58 Correct 146 ms 41848 KB Output is correct
59 Correct 146 ms 41848 KB Output is correct
60 Correct 14 ms 14456 KB Output is correct
61 Correct 14 ms 14456 KB Output is correct
62 Correct 14 ms 14456 KB Output is correct
63 Correct 14 ms 14456 KB Output is correct
64 Correct 14 ms 14456 KB Output is correct
65 Correct 17 ms 14460 KB Output is correct
66 Correct 14 ms 14456 KB Output is correct
67 Correct 14 ms 14456 KB Output is correct
68 Correct 17 ms 14392 KB Output is correct
69 Correct 14 ms 14456 KB Output is correct
70 Correct 15 ms 14584 KB Output is correct
71 Correct 14 ms 14456 KB Output is correct
72 Correct 14 ms 14584 KB Output is correct
73 Correct 15 ms 14428 KB Output is correct
74 Correct 14 ms 14456 KB Output is correct
75 Correct 14 ms 14456 KB Output is correct
76 Correct 14 ms 14456 KB Output is correct
77 Correct 14 ms 14456 KB Output is correct
78 Correct 14 ms 14456 KB Output is correct
79 Correct 14 ms 14428 KB Output is correct
80 Correct 14 ms 14456 KB Output is correct
81 Correct 14 ms 14456 KB Output is correct
82 Correct 15 ms 14464 KB Output is correct
83 Correct 15 ms 14456 KB Output is correct
84 Correct 14 ms 14428 KB Output is correct
85 Correct 14 ms 14456 KB Output is correct
86 Correct 14 ms 14456 KB Output is correct
87 Correct 14 ms 14460 KB Output is correct
88 Correct 20 ms 15372 KB Output is correct
89 Correct 24 ms 15992 KB Output is correct
90 Correct 26 ms 16376 KB Output is correct
91 Correct 87 ms 25592 KB Output is correct
92 Correct 177 ms 38008 KB Output is correct
93 Correct 375 ms 62168 KB Output is correct
94 Correct 374 ms 63224 KB Output is correct
95 Correct 376 ms 63012 KB Output is correct
96 Correct 368 ms 62712 KB Output is correct
97 Correct 375 ms 63832 KB Output is correct
98 Correct 380 ms 67492 KB Output is correct
99 Correct 424 ms 74188 KB Output is correct
100 Correct 366 ms 62588 KB Output is correct
101 Correct 299 ms 52088 KB Output is correct
102 Correct 505 ms 90172 KB Output is correct
103 Correct 318 ms 51648 KB Output is correct
104 Correct 292 ms 44380 KB Output is correct
105 Correct 209 ms 40176 KB Output is correct
106 Correct 405 ms 61228 KB Output is correct