#include "job.h"
#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define MAXN 200013
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int N;
int parent[MAXN];
pll arr[MAXN];
vi edge[MAXN];
vi ord[MAXN];
ll ans = 0;
vi comb(vi a, vi b)
{
vi res;
int iter = 0; pll rec = {0, 0};
FOR(i, 0, SZ(a))
{
while(iter < SZ(b) && (rec.fi + arr[b[iter]].fi) * arr[a[i]].se < (rec.se + arr[b[iter]].se) * arr[a[i]].fi)
{
res.PB(b[iter]);
rec.fi += arr[b[iter]].fi;
rec.se += arr[b[iter]].se;
iter++;
}
rec = {0, 0};
res.PB(a[i]);
}
while(iter < SZ(b))
{
res.PB(b[iter]); iter++;
}
return res;
}
void solve(int u)
{
for (int v : edge[u])
{
solve(v);
ord[u] = comb(ord[u], ord[v]);
}
ord[u].PB(u);
}
ll scheduling_cost(vi p, vi u, vi d)
{
N = SZ(p);
// cerr << "HI\n";
FOR(i, 0, N)
{
parent[i] = p[i];
if (i == 0)
{
parent[i] = N;
}
else
{
edge[parent[i]].PB(i);
}
arr[i] = {u[i], d[i]};
// cerr << "parent " << parent[i] << endl;
}
solve(0);
reverse(ALL(ord[0]));
ll t = 0;
// cerr << "ORD\n";
for (int u : ord[0])
{
// cerr << u << endl;
t += arr[u].se;
ans += t * arr[u].fi;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
12 ms |
9720 KB |
Output is correct |
3 |
Correct |
13 ms |
9848 KB |
Output is correct |
4 |
Correct |
19 ms |
13176 KB |
Output is correct |
5 |
Runtime error |
432 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
12 ms |
9720 KB |
Output is correct |
3 |
Correct |
11 ms |
9692 KB |
Output is correct |
4 |
Execution timed out |
3026 ms |
22272 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9720 KB |
Output is correct |
3 |
Correct |
11 ms |
9720 KB |
Output is correct |
4 |
Correct |
15 ms |
9896 KB |
Output is correct |
5 |
Correct |
367 ms |
10984 KB |
Output is correct |
6 |
Execution timed out |
3032 ms |
22196 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
9720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
9720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
12 ms |
9720 KB |
Output is correct |
3 |
Correct |
13 ms |
9848 KB |
Output is correct |
4 |
Correct |
19 ms |
13176 KB |
Output is correct |
5 |
Runtime error |
432 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |