Submission #635536

# Submission time Handle Problem Language Result Execution time Memory
635536 2022-08-26T11:36:17 Z tabr Job Scheduling (IOI19_job) C++17
0 / 100
3000 ms 62152 KB
#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) {
        vector<int> c;
        while (!a.empty() || !b.empty()) {
            vector<double> x, y;
            for (int i : a) {
                x.emplace_back(1.0 * d[i] / u[i]);
            }
            x.emplace_back(1e18);
            for (int i : b) {
                y.emplace_back(1.0 * d[i] / u[i]);
            }
            y.emplace_back(1e18);
            if (x < y) {
                c.emplace_back(a[0]);
                a.erase(a.begin());
            } else {
                c.emplace_back(b[0]);
                b.erase(b.begin());
            }
        }
        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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 548 ms 3548 KB Output is correct
5 Execution timed out 3038 ms 30264 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 8 ms 340 KB Output is correct
4 Execution timed out 3072 ms 15588 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 605 ms 568 KB Output is correct
5 Execution timed out 3073 ms 1336 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 3074 ms 62152 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 548 ms 3548 KB Output is correct
5 Execution timed out 3038 ms 30264 KB Time limit exceeded
6 Halted 0 ms 0 KB -