Submission #145733

# Submission time Handle Problem Language Result Execution time Memory
145733 2019-08-21T04:05:06 Z qkxwsm Job Scheduling (IOI19_job) C++14
0 / 100
3000 ms 262148 KB
#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 1000013

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 43 ms 47352 KB Output is correct
2 Correct 44 ms 47352 KB Output is correct
3 Correct 44 ms 47352 KB Output is correct
4 Correct 50 ms 50680 KB Output is correct
5 Runtime error 396 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 69 ms 47352 KB Output is correct
2 Correct 44 ms 47464 KB Output is correct
3 Correct 49 ms 47480 KB Output is correct
4 Execution timed out 3045 ms 58328 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 47224 KB Output is correct
2 Correct 44 ms 47296 KB Output is correct
3 Correct 54 ms 47224 KB Output is correct
4 Correct 49 ms 47372 KB Output is correct
5 Correct 409 ms 48640 KB Output is correct
6 Execution timed out 3050 ms 58292 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 47224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 47224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 47352 KB Output is correct
2 Correct 44 ms 47352 KB Output is correct
3 Correct 44 ms 47352 KB Output is correct
4 Correct 50 ms 50680 KB Output is correct
5 Runtime error 396 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Halted 0 ms 0 KB -