Submission #788399

# Submission time Handle Problem Language Result Execution time Memory
788399 2023-07-20T08:03:31 Z Sandarach151 Job Scheduling (CEOI12_jobs) C++17
100 / 100
165 ms 27572 KB
#include<bits/stdc++.h>
using namespace std;

bool func(int arr[], int m, int n, int nummachines, int maxdelay){
	bool res = true;
	int curpos = 0;
	for(int i=1; i<=n; i++){
		if(curpos>=m || !res){
			break;
		}
		else{
			int temp=curpos;
			for(int j=curpos; j<min(curpos+nummachines, m); j++){
				if(arr[j]<=i){
					temp++;
					if(i-arr[j]>maxdelay){
						res = false;
						break;
					}
				}
				else{
					break;
				}
			}
			curpos = temp;
		}
	}
	return curpos==m && res;
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, d, m;
	cin >> n >> d >> m;
	int arr[m];
	for(int i=0; i<m; i++){
		cin >> arr[i];
	}
	vector<int> arr2[n];
	for(int i=0; i<m; i++){
		arr2[arr[i]-1].push_back(i+1);
	}
	sort(arr, arr+m);
	int minmachine = 0;
	int maxmachine = m;
	while(minmachine<maxmachine){
		int mid = (minmachine+maxmachine)/2;
		bool res = func(arr, m, n, mid, d);
		if(!res){
			minmachine = mid+1;
		}
		else{
			maxmachine = mid;
		}
	}
	cout << minmachine << '\n';
	vector<pair<int, int>> vect;
	for(int i=0; i<n; i++){
		for(int j=0; j<arr2[i].size(); j++){
			vect.push_back({arr2[i][j], i});
		}
	}
	int pos = 0;
	for(int i=0; i<n; i++){
		int temp = pos;
		while(pos<min(temp+minmachine, m) && vect[pos].second<=i){
			cout << vect[pos].first << ' ';
			pos++;
		}
		cout << 0 << '\n';
	}		
	return 0;
}
	

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:61:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for(int j=0; j<arr2[i].size(); j++){
      |                ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3100 KB Output is correct
2 Correct 15 ms 3080 KB Output is correct
3 Correct 15 ms 3052 KB Output is correct
4 Correct 15 ms 3156 KB Output is correct
5 Correct 16 ms 3156 KB Output is correct
6 Correct 18 ms 3076 KB Output is correct
7 Correct 15 ms 3048 KB Output is correct
8 Correct 15 ms 3148 KB Output is correct
9 Correct 21 ms 5584 KB Output is correct
10 Correct 22 ms 5568 KB Output is correct
11 Correct 18 ms 3144 KB Output is correct
12 Correct 36 ms 5860 KB Output is correct
13 Correct 53 ms 9348 KB Output is correct
14 Correct 82 ms 12608 KB Output is correct
15 Correct 93 ms 14736 KB Output is correct
16 Correct 122 ms 18640 KB Output is correct
17 Correct 147 ms 22116 KB Output is correct
18 Correct 158 ms 23084 KB Output is correct
19 Correct 165 ms 27572 KB Output is correct
20 Correct 152 ms 22144 KB Output is correct