#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll
#ifdef HNO2
#define IOS
#else
#include <job.h>
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2
vector<int> G[maxn];
ll cost[maxn],t[maxn];
ll summ[maxn];
void dfs(int now,int p)
{
summ[now]+=cost[now];
for (int i:G[now])
if (i!=p) dfs(i,now),summ[now]+=summ[i];
}
struct frac
{
int x,y,id;
frac():x(0),y(0),id(0){}
frac(int _x,int _y,int _id):x(_x),y(_y),id(_id){}
bool operator<(const frac &rhs)const
{
return x*1ll*rhs.y<y*1ll*rhs.x;
}
bool operator>(const frac &rhs)const
{
return x*1ll*rhs.y>y*1ll*rhs.x;
}
};
long long scheduling_cost(std::vector<int> P, std::vector<int> U, std::vector<int> D)
{
int n=sz(P);
for (int i=1;i<n;i++)
G[P[i]+1].pb(i+1);
for (int i=1;i<=n;i++) t[i]=D[i-1],cost[i]=U[i-1];
dfs(1,-1);
priority_queue<frac> pq;
pq.push(frac(summ[1],t[1],1));
ll sum=0,ret=0;
while (!pq.empty())
{
frac now=pq.top();
pq.pop();
sum+=t[now.id];
ret+=cost[now.id]*sum;
for (int i:G[now.id])
pq.push(frac(summ[i],t[i],i));
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2680 KB |
Output is correct |
2 |
Correct |
8 ms |
2680 KB |
Output is correct |
3 |
Correct |
8 ms |
2680 KB |
Output is correct |
4 |
Correct |
8 ms |
2808 KB |
Output is correct |
5 |
Correct |
47 ms |
10616 KB |
Output is correct |
6 |
Correct |
81 ms |
18232 KB |
Output is correct |
7 |
Runtime error |
117 ms |
21240 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2680 KB |
Output is correct |
2 |
Correct |
9 ms |
2708 KB |
Output is correct |
3 |
Correct |
9 ms |
2680 KB |
Output is correct |
4 |
Runtime error |
120 ms |
21740 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2680 KB |
Output is correct |
2 |
Correct |
8 ms |
2680 KB |
Output is correct |
3 |
Correct |
8 ms |
2684 KB |
Output is correct |
4 |
Correct |
9 ms |
2808 KB |
Output is correct |
5 |
Correct |
16 ms |
3688 KB |
Output is correct |
6 |
Runtime error |
135 ms |
22060 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2680 KB |
Output is correct |
2 |
Correct |
8 ms |
2680 KB |
Output is correct |
3 |
Correct |
8 ms |
2680 KB |
Output is correct |
4 |
Correct |
8 ms |
2808 KB |
Output is correct |
5 |
Correct |
47 ms |
10616 KB |
Output is correct |
6 |
Correct |
81 ms |
18232 KB |
Output is correct |
7 |
Runtime error |
117 ms |
21240 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Halted |
0 ms |
0 KB |
- |