Submission #77251

# Submission time Handle Problem Language Result Execution time Memory
77251 2018-09-24T12:00:43 Z Vardanyan Job Scheduling (CEOI12_jobs) C++14
100 / 100
359 ms 21128 KB
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int N = 1000 * 100 + 7;
int day[N];
vector<int> g[N];
vector<int> as[N];
int main(){
	int n, d, m;
	scanf("%d%d%d", &n, &d, &m);
	for (int i = 1; i <= m; i++){
		int p;
		scanf("%d", &p);
		day[p]++;
		g[p].push_back(i);
	}
	int l = 1;
	int r = m;
	int ans = m;
	
	queue<int> q;
	while (l <= r){
		while (!q.empty()) q.pop();
		int mid = (l + r) / 2;
		for (int i = 1; i <= n; i++){
			int x = day[i];
			while (x--) q.push(i);
			bool f = true;
			int num = mid;
			while (!q.empty()){
				int v = q.front();
				if (i > v + d){
					f = false;
					break;
				}
				if (num > 0){
					q.pop();
					num--;
				}
				else break;
			}
		}
		if (q.empty()) {
			ans = mid;
			r = mid - 1;
		}
		else l = mid + 1;
	}
	int mid = ans;
	while (!q.empty()) q.pop();
	
	for (int i = 1; i <= n; i++){
		int x = day[i];
		while (x--) q.push(i);
		bool f = true;
		int num = mid;
		while (!q.empty()){
			int v = q.front();
			if (i > v + d){
				f = false;
				break;
			}
			if (num > 0){
				q.pop();
				num--;
				as[i].push_back(v);
			}
			else break;
		}
	}
	cout << ans << endl;
	for (int i = 1; i <= n; i++){
		for (int j = 0; j < as[i].size(); j++){
			int l = as[i][j];
			int e = g[l][g[l].size() - 1];
			printf("%d ", e);
			g[l].pop_back();
		}
		printf("%d\n", 0);
	}
	return 0;
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:30:9: warning: variable 'f' set but not used [-Wunused-but-set-variable]
    bool f = true;
         ^
jobs.cpp:57:8: warning: variable 'f' set but not used [-Wunused-but-set-variable]
   bool f = true;
        ^
jobs.cpp:75:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < as[i].size(); j++){
                   ~~^~~~~~~~~~~~~~
jobs.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &d, &m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &p);
   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 7152 KB Output is correct
2 Correct 38 ms 7268 KB Output is correct
3 Correct 39 ms 7268 KB Output is correct
4 Correct 43 ms 7304 KB Output is correct
5 Correct 37 ms 7396 KB Output is correct
6 Correct 36 ms 7396 KB Output is correct
7 Correct 35 ms 7396 KB Output is correct
8 Correct 34 ms 7396 KB Output is correct
9 Correct 51 ms 7396 KB Output is correct
10 Correct 49 ms 7396 KB Output is correct
11 Correct 44 ms 7396 KB Output is correct
12 Correct 71 ms 8620 KB Output is correct
13 Correct 104 ms 11488 KB Output is correct
14 Correct 178 ms 14032 KB Output is correct
15 Correct 175 ms 14032 KB Output is correct
16 Correct 246 ms 16528 KB Output is correct
17 Correct 359 ms 20276 KB Output is correct
18 Correct 289 ms 20276 KB Output is correct
19 Correct 350 ms 20888 KB Output is correct
20 Correct 327 ms 21128 KB Output is correct