Submission #775751

#TimeUsernameProblemLanguageResultExecution timeMemory
775751NK_Job Scheduling (CEOI12_jobs)C++17
100 / 100
176 ms26852 KiB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define pb push_back
#define sz(x) int(x.size())

template<class T> using V = vector<T>;

const int MX = 1e6+6;
const int nax = 1e5+5;

pair<int, int> in[MX];
V<int> C[nax], ans[nax];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, D, M; scanf("%d%d%d", &N, &D, &M);
	for(int i = 0; i < M; i++) {
		int t; scanf("%d", &t); --t;
		C[t].pb(i);
	}

	auto check = [&](int x, bool CREATE = 0) -> bool {
		int cur = 0, len = 0;
		for(int i = 0; i < N; i++) {
			if (cur < len && in[cur].first <= i) return 0;

			int end = i + D + 1;
			for(auto &c : C[i]) in[len++] = {end, c};

			if (CREATE) {
				int left = x;
				while(left-- && cur < len) ans[i].push_back(in[cur++].second);
			} else cur = min(len, cur + x);
		}

		return cur == len;
	};

	int lo = 1, hi = M;
	while(lo < hi) {
		int mid = (lo + hi) / 2;
		if (check(mid)) hi = mid;
		else lo = mid + 1;
	}

	check(lo, 1);

	printf("%d\n", lo);
	for(int i = 0; i < N; i++) {
		for(auto &x : ans[i]) printf("%d ", x + 1);
		printf("%d\n", 0);
	}

    return 0;
}


Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:21:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  int N, D, M; scanf("%d%d%d", &N, &D, &M);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:23:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   int t; scanf("%d", &t); --t;
      |          ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...