Submission #331185

# Submission time Handle Problem Language Result Execution time Memory
331185 2020-11-27T16:50:00 Z ttnhuy313 Job Scheduling (IOI19_job) C++14
5 / 100
128 ms 56940 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 1.0 * sum_d[i] / sum_cost[i] < 1.0 * sum_d[j] * sum_cost[j];
	});
	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];
}

# 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 6 ms 5356 KB Output is correct
5 Correct 33 ms 18412 KB Output is correct
6 Correct 65 ms 31596 KB Output is correct
7 Correct 91 ms 44268 KB Output is correct
8 Correct 119 ms 56812 KB Output is correct
9 Correct 128 ms 56812 KB Output is correct
10 Correct 126 ms 56812 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 120 ms 56940 KB Output is correct
13 Correct 121 ms 56812 KB Output is correct
14 Correct 120 ms 56556 KB Output is correct
15 Correct 128 ms 56556 KB Output is correct
16 Correct 120 ms 56556 KB Output is correct
17 Correct 122 ms 56556 KB Output is correct
18 Correct 125 ms 56556 KB Output is correct
19 Correct 123 ms 56428 KB Output is correct
20 Correct 125 ms 56428 KB Output is correct
# 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 Incorrect 4 ms 5100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 6 ms 5356 KB Output is correct
5 Correct 33 ms 18412 KB Output is correct
6 Correct 65 ms 31596 KB Output is correct
7 Correct 91 ms 44268 KB Output is correct
8 Correct 119 ms 56812 KB Output is correct
9 Correct 128 ms 56812 KB Output is correct
10 Correct 126 ms 56812 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 120 ms 56940 KB Output is correct
13 Correct 121 ms 56812 KB Output is correct
14 Correct 120 ms 56556 KB Output is correct
15 Correct 128 ms 56556 KB Output is correct
16 Correct 120 ms 56556 KB Output is correct
17 Correct 122 ms 56556 KB Output is correct
18 Correct 125 ms 56556 KB Output is correct
19 Correct 123 ms 56428 KB Output is correct
20 Correct 125 ms 56428 KB Output is correct
21 Correct 4 ms 5100 KB Output is correct
22 Incorrect 4 ms 5100 KB Output isn't correct
23 Halted 0 ms 0 KB -