This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "job.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fr first
#define sc second
long long n,as[200069],pst[200069],dp[200069];
pair<long long,long long> a[200069];
vector<long long> al[200069];
bitset<200069> vtd;
bool cmp(long long x,long long y)
{
return a[x].fr*a[y].sc<a[y].fr*a[x].sc;
}
void bd(long long x)
{
long long i,sz=al[x].size(),l;
vtd[x]=1;
dp[x]=pst[x];
for(i=0;i<sz;i++)
{
l=al[x][i];
if(!vtd[l])
{
bd(l);
dp[x]=min(dp[x],dp[l]);
}
}
}
bool cmp2(long long x,long long y)
{
return mp(dp[x],x)<mp(dp[y],y);
}
long long scheduling_cost(vector<int> p,vector<int> u,vector<int> d)
{
long long i,sm=0,z=0;
n=p.size();
for(i=1;i<=n;i++)
{
as[i]=i;
a[i]={d[i-1],u[i-1]};
if(i-1)
{
al[p[i-1]+1].push_back(i);
}
}
sort(as+1,as+n+1,cmp);
for(i=1;i<=n;i++)
{
pst[as[i]]=i;
as[i]=i;
}
bd(1);
sort(as+1,as+n+1,cmp2);
for(i=1;i<=n;i++)
{
sm+=a[as[i]].fr;
z+=a[as[i]].sc*sm;
}
return z;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |