Submission #211357

#TimeUsernameProblemLanguageResultExecution timeMemory
2113572qbingxuanJob Scheduling (IOI19_job)C++14
0 / 100
245 ms12148 KiB
//#include "job.h" #include <bits/stdc++.h> using namespace std; long long scheduling_cost(std::vector<int> p, std::vector<int> u, std::vector<int> d) { int n = p.size(); struct node { long long u, d; int id; bool operator<(node p)const{ return u*p.d < d*p.u; } }; long long ans = 0; vector<int> pa(n); iota(pa.begin(), pa.end(), 0); function<int(int)> anc = [&](int x){ return x==pa[x] ? x : pa[x]=anc(pa[x]); }; auto add = [&](int a, int i) { ans -= d[i] * u[a]; d[a] += d[i]; u[a] += u[i]; }; priority_queue<node> pq; for(int i = 0; i < n; i++) pq.push({u[i],d[i],i}); while(pq.size() > 1) { node x; do x=pq.top(), pq.pop(); while(pq.size() && (x.u!=u[x.id] || x.d!=d[x.id])); //if(pq.empty()) break; int i = x.id; if(p[i] == -1) continue; int a = anc(p[i]); pa[i] = a; add(a, i); pq.push({u[a],d[a],a}); } ans += 1LL * u[0] * d[0]; return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...