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;
int N;
int parent[MAXN], link[MAXN];
pll arr[MAXN];
vi edge[MAXN], tail[MAXN];
vi ord;
ll ans = 0;
priority_queue<pdi> pq;
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);
link[i] = parent[i];
arr[i] = {u[i], d[i]};
// cerr << "parent " << parent[i] << endl;
}
FOR(i, 0, N)
{
pq.push({1.0 * u[i] / d[i], i});
}
while(!pq.empty())
{
auto p = pq.top(); pq.pop();
int u = p.se;
// cerr << "u = " << u << endl;
if (link[u] == N)
{
ord.PB(u);
ord.insert(ord.end(), ALL(tail[u]));
}
else
{
tail[link[u]].PB(u);
}
for (int v : edge[u])
{
link[v] = link[u];
}
}
ll t = 0;
for (int u : ord)
{
// cerr << "u = " << u << endl;
t += arr[u].se;
ans += t * arr[u].fi;
}
return ans;
}
# | 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... |