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;
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;
typedef pair<ld, int> pdi;
typedef pair<pll, int> ppi;
int N;
int parent[MAXN], link[MAXN];
bitset<MAXN> taken;
vi edge[MAXN];
pll arr[MAXN];
struct cmp
{
bool operator() (const ppi &a, const ppi &b) const
{
if (a.fi.fi * b.fi.se != a.fi.se * b.fi.fi)
return a.fi.fi * b.fi.se < a.fi.se * b.fi.fi;
return a.se < b.se;
}
};
set<ppi, cmp> s;
ll ans = 0, t = 0;
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]};
s.insert({{arr[i].fi, arr[i].se}, i});
link[i] = parent[i];
ans += arr[i].fi * arr[i].se;
// cerr << "parent " << parent[i] << endl;
}
taken[N] = true;
FOR(i, 0, N)
{
int u = (prev(s.end())) -> se;
s.erase(prev(s.end()));
if (taken[link[u]])
{
ans += arr[u].fi * t;
t += arr[u].se;
taken[u] = true;
continue;
//cool gg
}
for (int v : edge[u])
{
link[v] = link[u];
}
int v = link[u];
s.erase(s.find({{arr[v].fi, arr[v].se}, v}));
ans += arr[v].se * arr[u].fi;
arr[v].fi += arr[u].fi;
arr[v].se += arr[u].se;
s.insert({{arr[v].fi, arr[v].se}, v});
}
return ans;
//yo uwant to take stuff with high fi/se first
}
# | 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... |