Submission #484520

#TimeUsernameProblemLanguageResultExecution timeMemory
4845201potato2potatoJob Scheduling (CEOI12_jobs)C++17
90 / 100
382 ms45692 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

using vi = vector<int>;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair

void setIO(string name = "") {
	cin.tie(0)->sync_with_stdio(0);
	if (sz(name)) {
		freopen((name + ".in") .c_str(), "r", stdin);
		freopen((name + ".out").c_str(), "w", stdout);
	}
}

int n, d, m;

pair<bool, vector<vi>> feas(int k, vector<pi> jobs) {
	int jobnum = 0;
	vector<vi> ans(n);
	for (int i=1; i<=n; i++) {
		for (int j = 0; j < k; j++) {
			if (jobs[jobnum].f > i) break;

			if (jobs[jobnum].f + d >= i) {
				ans[i - 1].push_back(jobs[jobnum++].s);
			} else {
				// can't fit this job
				return mp(false, ans);
			}

			if (jobnum == m) {
				// finished all jobs
				return mp(true, ans);
			}
		}
	}
	return mp(false, ans);
}
int main() {
	setIO();
	cin >> n >> d >> m;
	vector<pi> jobs(m);
	for (int i = 0; i < m; i++) {
		int day;
		cin >> day;
		jobs[i] = {day, i + 1};
	}
	sort(all(jobs));

	int lo = 1, hi = m;
	vector<vi> ret;
	pair<bool, vector<vi>> res;
	while (lo < hi) {
		int mid = (lo + hi) / 2;
		res = feas(mid, jobs);
		if(res.f) {
			hi = mid;
			ret = res.s;
		} else {
			lo = mid + 1;
		}
	}
	cout << lo << "\n";

	for (int i = 0; i < n; i++) {
		for (auto idx : ret[i]) {
			cout << idx << " ";
		}
		cout << 0 << "\n";
	}
}

Compilation message (stderr)

jobs.cpp: In function 'void setIO(std::string)':
jobs.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen((name + ".in") .c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   freopen((name + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...