# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
314844 | 2020-10-21T13:25:19 Z | blue | Job Scheduling (IOI19_job) | C++17 | 0 ms | 0 KB |
#include "job.h" #include <vector> #include <algorithm> #include <set> using namespace std; struct job { long long u; long long d; vector<int> children; }; bool operator < (job A, job B) { return A.u*B.d > B.u*A.d; } long long scheduling_cost(vector<int> p, vector<int> u, vector<int> d) { long long res = 0; int n = p.size(); job J[n]; vector<int> v; for(int i = 0; i < n; i++) { J[i] = job{u[i], d[i], v}; if(i > 0) J[p[i]].children.push_back(i); } long long t = 0; set<job> S; S.insert(J[0]); job j; while(!S.empty()) { j = S.front(); S.erase(S.front()); for(int k: j.children) S.insert(J[k]); t += j.d; res += t * j.u; } return res; }