Submission #315765

# Submission time Handle Problem Language Result Execution time Memory
315765 2020-10-23T21:53:21 Z tincamatei Job Scheduling (IOI19_job) C++14
24 / 100
327 ms 60664 KB
#include "job.h"
#include <vector>
#include <set>
#include <cstdio>

const int MAX_N = 200000;

long long res;

std::vector<int> graph[MAX_N];

struct DSUNode {
    int nod, sd, su;

    DSUNode(int _nod, int _sd, int _su) {
        nod = _nod;
        sd = _sd;
        su = _su;
    }

    bool operator< (const DSUNode x) const {
        return (long long)sd * x.su < (long long)su * x.sd ||
            ((long long)sd * x.su == (long long)su * x.sd && nod < x.nod);
    }
};

struct DSU {
    int sd, su;
    std::set<DSUNode> extended_neighbours;
} dsu[MAX_N];

void join(int a, int b) {
    res = res + (long long)dsu[a].sd * dsu[b].su;
    dsu[a].sd += dsu[b].sd;
    dsu[a].su += dsu[b].su;
    
    dsu[a].extended_neighbours.erase({b, dsu[b].sd, dsu[b].su});
    if(dsu[a].extended_neighbours.size() < dsu[b].extended_neighbours.size())
        dsu[a].extended_neighbours.swap(dsu[b].extended_neighbours);
    
    for(auto it: dsu[b].extended_neighbours)
        dsu[a].extended_neighbours.insert(it);
    dsu[b].extended_neighbours.clear();
}

void dfs(int nod) {
    for(auto it: graph[nod]) {
        dfs(it);
        dsu[nod].extended_neighbours.insert({it, dsu[it].sd, dsu[it].su});
    }
    
    while(!dsu[nod].extended_neighbours.empty()
    && DSUNode(nod, dsu[nod].sd, dsu[nod].su) < *dsu[nod].extended_neighbours.begin())
        join(nod, dsu[nod].extended_neighbours.begin()->nod);
}

long long scheduling_cost(std::vector<int> p, std::vector<int> u, std::vector<int> d) {
    int n = u.size();
    for(int i = 0; i < n; ++i) {
        dsu[i] = {d[i], u[i]};
        res = res + (long long)u[i] * d[i];
    }
    for(int i = 1; i < n; ++i)
        graph[p[i]].push_back(i);
    
    dfs(0);
    
    while(!dsu[0].extended_neighbours.empty())
        join(0, dsu[0].extended_neighbours.begin()->nod);

    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16000 KB Output is correct
2 Correct 10 ms 16000 KB Output is correct
3 Correct 11 ms 16000 KB Output is correct
4 Correct 11 ms 16128 KB Output is correct
5 Correct 44 ms 24952 KB Output is correct
6 Correct 78 ms 34044 KB Output is correct
7 Correct 112 ms 43000 KB Output is correct
8 Correct 147 ms 51960 KB Output is correct
9 Correct 146 ms 52036 KB Output is correct
10 Correct 144 ms 52012 KB Output is correct
11 Correct 11 ms 16000 KB Output is correct
12 Correct 143 ms 51964 KB Output is correct
13 Correct 146 ms 51960 KB Output is correct
14 Correct 143 ms 52088 KB Output is correct
15 Correct 144 ms 52216 KB Output is correct
16 Correct 142 ms 51960 KB Output is correct
17 Correct 142 ms 51944 KB Output is correct
18 Correct 146 ms 51960 KB Output is correct
19 Correct 149 ms 60664 KB Output is correct
20 Correct 144 ms 52088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16000 KB Output is correct
2 Correct 11 ms 16000 KB Output is correct
3 Correct 11 ms 16000 KB Output is correct
4 Correct 327 ms 33972 KB Output is correct
5 Correct 279 ms 34004 KB Output is correct
6 Correct 281 ms 34028 KB Output is correct
7 Correct 273 ms 34028 KB Output is correct
8 Correct 281 ms 34064 KB Output is correct
9 Correct 277 ms 34028 KB Output is correct
10 Correct 280 ms 33936 KB Output is correct
11 Correct 284 ms 34028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16000 KB Output is correct
2 Correct 10 ms 16000 KB Output is correct
3 Correct 11 ms 16000 KB Output is correct
4 Correct 11 ms 16000 KB Output is correct
5 Correct 18 ms 16896 KB Output is correct
6 Correct 283 ms 34028 KB Output is correct
7 Correct 273 ms 34028 KB Output is correct
8 Correct 271 ms 34028 KB Output is correct
9 Correct 265 ms 34028 KB Output is correct
10 Correct 10 ms 16000 KB Output is correct
11 Correct 12 ms 16128 KB Output is correct
12 Correct 17 ms 16768 KB Output is correct
13 Correct 18 ms 16896 KB Output is correct
14 Correct 271 ms 34028 KB Output is correct
15 Correct 264 ms 34028 KB Output is correct
16 Correct 277 ms 34028 KB Output is correct
17 Correct 270 ms 34028 KB Output is correct
18 Correct 267 ms 34028 KB Output is correct
19 Correct 265 ms 34028 KB Output is correct
20 Correct 267 ms 34028 KB Output is correct
21 Correct 274 ms 34056 KB Output is correct
22 Correct 271 ms 34028 KB Output is correct
23 Correct 271 ms 34028 KB Output is correct
24 Correct 270 ms 34028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 16000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16000 KB Output is correct
2 Incorrect 10 ms 16000 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16000 KB Output is correct
2 Correct 10 ms 16000 KB Output is correct
3 Correct 11 ms 16000 KB Output is correct
4 Correct 11 ms 16128 KB Output is correct
5 Correct 44 ms 24952 KB Output is correct
6 Correct 78 ms 34044 KB Output is correct
7 Correct 112 ms 43000 KB Output is correct
8 Correct 147 ms 51960 KB Output is correct
9 Correct 146 ms 52036 KB Output is correct
10 Correct 144 ms 52012 KB Output is correct
11 Correct 11 ms 16000 KB Output is correct
12 Correct 143 ms 51964 KB Output is correct
13 Correct 146 ms 51960 KB Output is correct
14 Correct 143 ms 52088 KB Output is correct
15 Correct 144 ms 52216 KB Output is correct
16 Correct 142 ms 51960 KB Output is correct
17 Correct 142 ms 51944 KB Output is correct
18 Correct 146 ms 51960 KB Output is correct
19 Correct 149 ms 60664 KB Output is correct
20 Correct 144 ms 52088 KB Output is correct
21 Correct 12 ms 16000 KB Output is correct
22 Correct 11 ms 16000 KB Output is correct
23 Correct 11 ms 16000 KB Output is correct
24 Correct 327 ms 33972 KB Output is correct
25 Correct 279 ms 34004 KB Output is correct
26 Correct 281 ms 34028 KB Output is correct
27 Correct 273 ms 34028 KB Output is correct
28 Correct 281 ms 34064 KB Output is correct
29 Correct 277 ms 34028 KB Output is correct
30 Correct 280 ms 33936 KB Output is correct
31 Correct 284 ms 34028 KB Output is correct
32 Correct 11 ms 16000 KB Output is correct
33 Correct 10 ms 16000 KB Output is correct
34 Correct 11 ms 16000 KB Output is correct
35 Correct 11 ms 16000 KB Output is correct
36 Correct 18 ms 16896 KB Output is correct
37 Correct 283 ms 34028 KB Output is correct
38 Correct 273 ms 34028 KB Output is correct
39 Correct 271 ms 34028 KB Output is correct
40 Correct 265 ms 34028 KB Output is correct
41 Correct 10 ms 16000 KB Output is correct
42 Correct 12 ms 16128 KB Output is correct
43 Correct 17 ms 16768 KB Output is correct
44 Correct 18 ms 16896 KB Output is correct
45 Correct 271 ms 34028 KB Output is correct
46 Correct 264 ms 34028 KB Output is correct
47 Correct 277 ms 34028 KB Output is correct
48 Correct 270 ms 34028 KB Output is correct
49 Correct 267 ms 34028 KB Output is correct
50 Correct 265 ms 34028 KB Output is correct
51 Correct 267 ms 34028 KB Output is correct
52 Correct 274 ms 34056 KB Output is correct
53 Correct 271 ms 34028 KB Output is correct
54 Correct 271 ms 34028 KB Output is correct
55 Correct 270 ms 34028 KB Output is correct
56 Incorrect 11 ms 16000 KB Output isn't correct
57 Halted 0 ms 0 KB -