#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
long long scheduling_cost(vector<int> p, vector<int> u, vector<int> d) {
int n = (int) p.size();
vector<vector<int>> g(n);
for (int i = 1; i < n; i++) {
g[p[i]].emplace_back(i);
}
auto Merge = [&](vector<int> a, vector<int> b) {
int sa = (int) a.size();
int sb = (int) b.size();
vector<int> c;
for (int i = 0, j = 0; i <= sa; i++) {
while (j < sb && (i == sa || d[b[j]] * u[a[i]] < d[a[i]] * u[b[j]])) {
c.emplace_back(b[j]);
j++;
}
if (i == sa) {
break;
}
c.emplace_back(a[i]);
}
return c;
/*
vector<long long> da(sa + 1), db(sb + 1);
for (int i = 0; i < sa; i++) {
da[i + 1] = da[i] + d[a[i]];
}
for (int i = 0; i < sb; i++) {
db[i + 1] = db[i] + d[b[i]];
}
const long long inf = (long long) 1e18;
vector<vector<long long>> dp(sa + 1, vector<long long>(sb + 1, inf));
dp[0][0] = 0;
for (int i = 0; i <= sa; i++) {
for (int j = 0; j <= sb; j++) {
if (i < sa) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (da[i + 1] + db[j]) * u[a[i]]);
}
if (j < sb) {
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (da[i] + db[j + 1]) * u[b[j]]);
}
}
}
vector<int> c;
int x = sa, y = sb;
while (x > 0 || y > 0) {
if (x > 0 && dp[x][y] == dp[x - 1][y] + (da[x] + db[y]) * u[a[x - 1]]) {
c.emplace_back(a[x - 1]);
x--;
} else if (y > 0 && dp[x][y] == dp[x][y - 1] + (da[x] + db[y]) * u[b[y - 1]]) {
c.emplace_back(b[y - 1]);
y--;
} else {
assert(false);
}
}
reverse(c.begin(), c.end());
return c;
*/
};
vector<vector<int>> a(n);
function<void(int)> Dfs = [&](int v) {
for (int to : g[v]) {
Dfs(to);
a[v] = Merge(a[v], a[to]);
}
a[v].insert(a[v].begin(), v);
};
Dfs(0);
long long res = 0;
long long t = 0;
for (int i : a[0]) {
t += d[i];
res += t * u[i];
}
return res;
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
debug(scheduling_cost({-1, 0, 0}, {5, 2, 5}, {3, 4, 1}));
return 0;
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
3668 KB |
Output is correct |
5 |
Runtime error |
281 ms |
262144 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Execution timed out |
3082 ms |
19200 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
208 ms |
1752 KB |
Output is correct |
6 |
Execution timed out |
3059 ms |
19820 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
299 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
3668 KB |
Output is correct |
5 |
Runtime error |
281 ms |
262144 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |