Submission #331182

# Submission time Handle Problem Language Result Execution time Memory
331182 2020-11-27T16:46:42 Z ttnhuy313 Job Scheduling (IOI19_job) C++14
24 / 100
143 ms 58476 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long

const int N = 2e5 + 5;
int n, sum_cost[N], sum_d[N], dp[N], cost[N], d[N];
vector <int> adj[N];

void dfs(int u) {
	sum_cost[u] = cost[u];
	sum_d[u] = d[u];
	vector <int> V; V.clear();
	for (int v : adj[u]) {
		V.push_back(v);
		dfs(v);
		sum_cost[u] += sum_cost[v];
		sum_d[u] += sum_d[v];
	}
	sort(V.begin(), V.end(), [](int i, int j) {
		return sum_d[i] * sum_cost[j] < sum_d[j] * sum_cost[i];
	});
	dp[u] = d[u] * cost[u];
	int pre = d[u];
	for (int v : V) {
		dp[u] += dp[v] + pre * sum_cost[v];
		pre += sum_d[v];
	}
}

int scheduling_cost(vector <int32_t> p, vector <int32_t> c, vector <int32_t> time) {	
	n = p.size();
	for (int i = 0; i < n; ++i) {
		cost[i] = c[i];
		d[i] = time[i];
	}
	for (int i = 1; i < n; ++i) {
		adj[p[i]].push_back(i);
	}
	dfs(0);
	return dp[0];
}


// signed main() {
// 	ios_base::sync_with_stdio(0); cin.tie(0);
// 	freopen("JOB.INP", "r", stdin);
// 	freopen("JOB.OUT", "w", stdout);

// 	int n;
// 	cin >> n;
// 	vector <int32_t> p, c, time;
// 	p.assign(n, 0); c.assign(n, 0); time.assign(n, 0);
// 	for (int i = 0; i < n; ++i) {
// 		cin >> p[i];
// 	}
// 	for (int i = 0; i < n; ++i)
// 		cin >> c[i];
// 	for (int i = 0; i < n; ++i)
// 		cin >> time[i];
// 	cout << scheduling_cost(p, c, time) << endl;

// 	return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 3 ms 5100 KB Output is correct
3 Correct 3 ms 5100 KB Output is correct
4 Correct 4 ms 5356 KB Output is correct
5 Correct 34 ms 18412 KB Output is correct
6 Correct 65 ms 31724 KB Output is correct
7 Correct 100 ms 45036 KB Output is correct
8 Correct 125 ms 58348 KB Output is correct
9 Correct 127 ms 58348 KB Output is correct
10 Correct 127 ms 58348 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 126 ms 58348 KB Output is correct
13 Correct 140 ms 58348 KB Output is correct
14 Correct 143 ms 58348 KB Output is correct
15 Correct 122 ms 58476 KB Output is correct
16 Correct 124 ms 58348 KB Output is correct
17 Correct 136 ms 58348 KB Output is correct
18 Correct 126 ms 58348 KB Output is correct
19 Correct 122 ms 58368 KB Output is correct
20 Correct 125 ms 58348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 103 ms 22616 KB Output is correct
5 Correct 116 ms 22668 KB Output is correct
6 Correct 108 ms 22620 KB Output is correct
7 Correct 105 ms 22620 KB Output is correct
8 Correct 113 ms 22644 KB Output is correct
9 Correct 102 ms 22620 KB Output is correct
10 Correct 111 ms 22748 KB Output is correct
11 Correct 112 ms 22620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 9 ms 6124 KB Output is correct
6 Correct 113 ms 23164 KB Output is correct
7 Correct 110 ms 23132 KB Output is correct
8 Correct 117 ms 23132 KB Output is correct
9 Correct 112 ms 23260 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 5 ms 5228 KB Output is correct
12 Correct 8 ms 5996 KB Output is correct
13 Correct 9 ms 6124 KB Output is correct
14 Correct 116 ms 23260 KB Output is correct
15 Correct 113 ms 23132 KB Output is correct
16 Correct 113 ms 23132 KB Output is correct
17 Correct 115 ms 23132 KB Output is correct
18 Correct 111 ms 23132 KB Output is correct
19 Correct 120 ms 23260 KB Output is correct
20 Correct 120 ms 23132 KB Output is correct
21 Correct 111 ms 23132 KB Output is correct
22 Correct 109 ms 23132 KB Output is correct
23 Correct 112 ms 23256 KB Output is correct
24 Correct 109 ms 23132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Incorrect 4 ms 5100 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 3 ms 5100 KB Output is correct
3 Correct 3 ms 5100 KB Output is correct
4 Correct 4 ms 5356 KB Output is correct
5 Correct 34 ms 18412 KB Output is correct
6 Correct 65 ms 31724 KB Output is correct
7 Correct 100 ms 45036 KB Output is correct
8 Correct 125 ms 58348 KB Output is correct
9 Correct 127 ms 58348 KB Output is correct
10 Correct 127 ms 58348 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 126 ms 58348 KB Output is correct
13 Correct 140 ms 58348 KB Output is correct
14 Correct 143 ms 58348 KB Output is correct
15 Correct 122 ms 58476 KB Output is correct
16 Correct 124 ms 58348 KB Output is correct
17 Correct 136 ms 58348 KB Output is correct
18 Correct 126 ms 58348 KB Output is correct
19 Correct 122 ms 58368 KB Output is correct
20 Correct 125 ms 58348 KB Output is correct
21 Correct 4 ms 5100 KB Output is correct
22 Correct 4 ms 5100 KB Output is correct
23 Correct 4 ms 5100 KB Output is correct
24 Correct 103 ms 22616 KB Output is correct
25 Correct 116 ms 22668 KB Output is correct
26 Correct 108 ms 22620 KB Output is correct
27 Correct 105 ms 22620 KB Output is correct
28 Correct 113 ms 22644 KB Output is correct
29 Correct 102 ms 22620 KB Output is correct
30 Correct 111 ms 22748 KB Output is correct
31 Correct 112 ms 22620 KB Output is correct
32 Correct 4 ms 5100 KB Output is correct
33 Correct 4 ms 5100 KB Output is correct
34 Correct 4 ms 5100 KB Output is correct
35 Correct 4 ms 5100 KB Output is correct
36 Correct 9 ms 6124 KB Output is correct
37 Correct 113 ms 23164 KB Output is correct
38 Correct 110 ms 23132 KB Output is correct
39 Correct 117 ms 23132 KB Output is correct
40 Correct 112 ms 23260 KB Output is correct
41 Correct 4 ms 5100 KB Output is correct
42 Correct 5 ms 5228 KB Output is correct
43 Correct 8 ms 5996 KB Output is correct
44 Correct 9 ms 6124 KB Output is correct
45 Correct 116 ms 23260 KB Output is correct
46 Correct 113 ms 23132 KB Output is correct
47 Correct 113 ms 23132 KB Output is correct
48 Correct 115 ms 23132 KB Output is correct
49 Correct 111 ms 23132 KB Output is correct
50 Correct 120 ms 23260 KB Output is correct
51 Correct 120 ms 23132 KB Output is correct
52 Correct 111 ms 23132 KB Output is correct
53 Correct 109 ms 23132 KB Output is correct
54 Correct 112 ms 23256 KB Output is correct
55 Correct 109 ms 23132 KB Output is correct
56 Incorrect 4 ms 5100 KB Output isn't correct
57 Halted 0 ms 0 KB -