#include "job.h"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pld pair<ld, ll>
#define fi first
#define se second
using namespace std;
const int N = 4e5+5;
const int M = 205;
const ld mod = 1e12;
const ld base = 1e-7;
ll n, m, k, ans, lab[N], cost[N], tim[N], id[N], par[N], t;
ld d[N];
struct node
{
bool operator ()(ll x, ll y) const
{
if(cost[x] * tim[y] == cost[y] * tim[x])return x < y;
cost[x] * tim[y] > cost[y] * tim[x];
}
};
ll findp(ll u)
{
return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
}
priority_queue<pld> pq;
ll scheduling_cost(vector<int> p, vector<int> c, vector<int> di)
{
n = p.size();
fill_n(lab, n+1, -1);
for(int i = 1; i <= n; i ++)
{
par[i] = p[i-1]+1;
cost[i] = c[i-1];
tim[i] = di[i-1];
d[i] = mod * cost[i] / tim[i];
pq.push({d[i], i});
//cout << cost[i] <<" "<<tim[i]<<" ";
}
while(!pq.empty())
{
pld u = pq.top();
pq.pop();
if(abs(d[u.se]-u.fi) > base)continue;
//cout << (ld)u.fi <<" ";
if(!par[u.se] || d[findp(par[u.se])] == -1)
{
t += tim[u.se];
ans += t * cost[u.se];
d[u.se] = -1;
}
else
{
ll v = findp(par[u.se]);
ans -= cost[v] * tim[u.se];
cost[v] += cost[u.se];
tim[v] += tim[u.se];
lab[u.se] = v;
d[v] = mod * cost[v] / tim[v];
pq.push({d[v], v});
}
}
return ans;
}
Compilation message
job.cpp: In member function 'bool node::operator()(long long int, long long int) const':
job.cpp:22:20: warning: statement has no effect [-Wunused-value]
22 | cost[x] * tim[y] > cost[y] * tim[x];
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
59 ms |
5552 KB |
Output is correct |
6 |
Correct |
128 ms |
10640 KB |
Output is correct |
7 |
Correct |
239 ms |
18480 KB |
Output is correct |
8 |
Correct |
342 ms |
20780 KB |
Output is correct |
9 |
Correct |
288 ms |
20832 KB |
Output is correct |
10 |
Correct |
309 ms |
20908 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
298 ms |
20828 KB |
Output is correct |
13 |
Correct |
290 ms |
20904 KB |
Output is correct |
14 |
Correct |
263 ms |
20836 KB |
Output is correct |
15 |
Correct |
215 ms |
20768 KB |
Output is correct |
16 |
Incorrect |
237 ms |
20768 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
188 ms |
20816 KB |
Output is correct |
5 |
Correct |
183 ms |
20828 KB |
Output is correct |
6 |
Correct |
187 ms |
20776 KB |
Output is correct |
7 |
Correct |
174 ms |
20772 KB |
Output is correct |
8 |
Correct |
170 ms |
20768 KB |
Output is correct |
9 |
Correct |
182 ms |
20824 KB |
Output is correct |
10 |
Correct |
179 ms |
20804 KB |
Output is correct |
11 |
Correct |
181 ms |
20828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
7 ms |
1580 KB |
Output is correct |
6 |
Correct |
184 ms |
20828 KB |
Output is correct |
7 |
Correct |
174 ms |
20828 KB |
Output is correct |
8 |
Correct |
181 ms |
20800 KB |
Output is correct |
9 |
Correct |
176 ms |
20776 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
8 ms |
1480 KB |
Output is correct |
13 |
Correct |
7 ms |
1608 KB |
Output is correct |
14 |
Correct |
174 ms |
20824 KB |
Output is correct |
15 |
Correct |
172 ms |
20896 KB |
Output is correct |
16 |
Correct |
175 ms |
20768 KB |
Output is correct |
17 |
Correct |
169 ms |
20824 KB |
Output is correct |
18 |
Correct |
173 ms |
20912 KB |
Output is correct |
19 |
Correct |
173 ms |
20768 KB |
Output is correct |
20 |
Correct |
171 ms |
20844 KB |
Output is correct |
21 |
Correct |
176 ms |
20896 KB |
Output is correct |
22 |
Correct |
169 ms |
20772 KB |
Output is correct |
23 |
Correct |
189 ms |
20764 KB |
Output is correct |
24 |
Correct |
172 ms |
20788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
310 ms |
20912 KB |
Output is correct |
3 |
Correct |
290 ms |
20772 KB |
Output is correct |
4 |
Correct |
326 ms |
20828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
59 ms |
5552 KB |
Output is correct |
6 |
Correct |
128 ms |
10640 KB |
Output is correct |
7 |
Correct |
239 ms |
18480 KB |
Output is correct |
8 |
Correct |
342 ms |
20780 KB |
Output is correct |
9 |
Correct |
288 ms |
20832 KB |
Output is correct |
10 |
Correct |
309 ms |
20908 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
298 ms |
20828 KB |
Output is correct |
13 |
Correct |
290 ms |
20904 KB |
Output is correct |
14 |
Correct |
263 ms |
20836 KB |
Output is correct |
15 |
Correct |
215 ms |
20768 KB |
Output is correct |
16 |
Incorrect |
237 ms |
20768 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |