제출 #563589

#제출 시각아이디문제언어결과실행 시간메모리
563589CodurrJob Scheduling (CEOI12_jobs)C++14
100 / 100
372 ms22540 KiB
#include "bits/stdc++.h"
using namespace std;

#define int long long //Avoid if time complexity very close to limit
#define ll long long
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define f first
#define s second

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

//Imp consts
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 1;
const int INF = 1e18 + 5;
const double pi = 3.14159265358979323846;
const double ep = 1e-20;

signed main() {
	setIO();
	int n, d, m;
	cin >> n >> d >> m;
	vector<int> st(n + 1), en(n + 1);
	vector<pair<int, int>> task;
	for (int i = 0; i < m; i++) {
		int x;
		cin >> x;
		task.push_back({x, i + 1});
		st[x]++;
		en[x + d]++;
	}
	sort(all(task));
	int l = 0, r = 1e7;
	while (r > l + 1) {
		int m = l + (r - l) / 2;
		int done = 0, due = 0;
		bool ok = 1;
		for (int i = 1; i <= n; i++) {
			due += st[i];
			int x = due;
			due -= min(m, x);
			done += min(m, x);
			if (en[i]) {
				if (done < en[i]) {
					ok = 0;
					break;
				}
				done -= en[i];
			}
		}
		if (ok)
			r = m;
		else
			l = m;
	}
	cout << r << '\n';;
	l = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= r; j++) {
			if (l < sz(task) && task[l].f <= i) {
				cout << task[l].s << " ";
				l++;
			}
		}
		cout << "0\n" ;
	}
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

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