Submission #253254

# Submission time Handle Problem Language Result Execution time Memory
253254 2020-07-27T14:32:12 Z anubhavdhar Job Scheduling (CEOI12_jobs) C++14
0 / 100
45 ms 65540 KB
#include<bits/stdc++.h>

#define ll long long int
#define pb push_back
#define mp make_pair
#define FOR(i,n) for(i=0;i<(n);++i)
#define FORe(i,n) for(i=1;i<=(n);++i)
#define FORr(i,a,b) for(i=(a);i<(b);++i)
#define FORrev(i,n) for(i=(n);i>=0;--i)
#define F0R(i,n) for(int i=0;i<(n);++i)
#define F0Re(i,n) for(int i=1;i<=(n);++i)
#define F0Rr(i,a,b) for(ll i=(a);i<(b);++i)
#define F0Rrev(i,n) for(int i=(n);i>=0;--i)
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define ff first
#define ss second
#define cd complex<double>
#define vcd vector<cd>
#define ldd long double
#define dbgLine cerr<<"Line : "<<__LINE__<<'\n'
#define all(x) (x).begin(),(x).end()

using namespace std;

const short int __PRECISION = 10;

const ll MOD = 1e9+7;
const ll INF = 1e17 + 1101;
const ll LOGN = 17;
const ll MAXN = 1e5+5;
const ll ROOTN = 320;

const ldd PI = acos(-1);
const ldd EPS = 1e-7;

int N, M, D;
queue<int> doing, waiting, job[MAXN];
int A[MAXN];
vector<int> V;

inline void tmwst()
{
	int a = 4343, b = 24323;
	while(a != 4344)
	{
		a = __gcd(a, b);
	}
}

inline void init()
{
	while(!doing.empty())	doing.pop();
	while(!waiting.empty())	waiting.pop();
}

inline bool doable(int R)
{
	init();

	int tmp[N+1];
	F0Re(i, N)
		tmp[i] = A[i];

	F0Re(i, N)
	{
		if((!waiting.empty()) and i - (int)waiting.front() > D)
			return false;
		// int L = tmp[i];
		while((!waiting.empty()) and ((int)doing.size() < R))
		{
			doing.push(waiting.front());
			waiting.pop();
		}
		F0R(j, tmp[i])
		{
			if((int)doing.size() < R)
				doing.push(i);
			else
				waiting.push(i);
		}
		while(!doing.empty())	doing.pop();
	}

	return true;
}

inline void solve(int R)
{
	cout<<R<<'\n';

	init();

	int tmp[N+1];
	F0Re(i, N)
		tmp[i] = A[i];

	F0Re(i, N)
	{
		if((!waiting.empty()) and i - (int)waiting.front() > D)
		// int L = tmp[i];
		while((!waiting.empty()) and ((int)doing.size() < R))
		{
			doing.push(waiting.front());
			waiting.pop();
		}
		F0R(j, tmp[i])
		{
			if((int)doing.size() < R)
				doing.push(i);
			else
				waiting.push(i);
		}
		while(!doing.empty())
		{
			if(job[doing.front()].empty())
				tmwst();
			cout << (job[doing.front()].front() + 1) << ' ';
			job[doing.front()].pop();
			doing.pop();
		}

		cout<<"0\n";
	}

}

int main()
{
	/*
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	*/
	

	int j, hi, lo, mid;
	cin>>N>>D>>M;

	F0Re(i, N)
		A[i] = 0;

	exit(0);
  
	F0R(i, M)
	{
		cin>>j;
		V.pb(j);
		job[j].push(i);
		++A[j];
	}
  

	lo = 0, hi = M;
	while(lo < hi - 1)
	{
		mid = (hi + lo)/2;
		if(doable(mid))
			hi = mid;
		else
			lo = mid;
	}
  
	solve(hi);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 43 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 41 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 41 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 41 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 41 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 36 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 42 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 41 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 36 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 45 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 41 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 37 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 36 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 43 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 41 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 40 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 41 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 40 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 36 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Runtime error 43 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)