Submission #146752

# Submission time Handle Problem Language Result Execution time Memory
146752 2019-08-26T00:55:43 Z qkxwsm Job Scheduling (IOI19_job) C++14
0 / 100
295 ms 67112 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 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];
pii arr[MAXN];

struct cmp1
{
	bool operator() (const ppi &a, const ppi &b) const
	{
		return a.fi.fi * b.fi.se < a.fi.se * b.fi.fi;
	}
};

set<ppi, cmp1> s;
ll ans = 0, t = 0;

bool cmp(pll a, pll b)
{
	return a.fi * b.se > a.se * b.fi;
}
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
1 Correct 6 ms 5112 KB Output is correct
2 Runtime error 15 ms 10148 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Runtime error 13 ms 10104 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5100 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Runtime error 24 ms 12284 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Runtime error 295 ms 67112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Runtime error 13 ms 9976 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Runtime error 15 ms 10148 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -