Submission #870307

# Submission time Handle Problem Language Result Execution time Memory
870307 2023-11-07T12:37:24 Z nhatvpm Job Scheduling (CEOI12_jobs) C++17
100 / 100
199 ms 13908 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld=long double;

void setIO(string name) {
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}

int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

void solve(){
	int n,d,m;
	cin>>n>>d>>m;
	vector<pair<int,int>> a(m);
	for (int i=0;i<m;i++){
		int x;
		cin>>x;
		a[i]={x,i+1};
	}
	sort(a.begin(),a.end());
	int lo=1,hi=m;
	while (lo<hi){
		int mid=lo+(hi-lo)/2;
		bool ok=1;
		for (int i=1,x=0;i<=n&&x<m;i++){
			int y=x;
			for (int j=y;j<=min(m-1,y+mid-1);j++){
				if (a[j].first>i) break;
				if (a[j].first+d<i){
					ok=0;
					goto esc;
				}
				x++;
			}
		}
		esc:
		if (ok) hi=mid;
		else lo=mid+1;
	}
	cout<<lo<<'\n';
	int x=0;
	for (int i=1;i<=n;i++){
		if (x==m){
			cout<<"0\n";
			continue;
		}
		int k=min(m-1,x+lo-1);
		for (int j=x;j<=k;j++){
			if (a[j].first>i) break;
			cout<<a[j].second<<' ';
			x++;
		}
		
		cout<<"0\n";
	}
	
	
	
	
	
	
	
	
}


int main(){
	//setIO("");
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	int tc=1;
	//cin>>tc;
	while (tc--){
		solve();
	}
}

Compilation message

jobs.cpp: In function 'void setIO(std::string)':
jobs.cpp:8:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:9:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1628 KB Output is correct
2 Correct 14 ms 1628 KB Output is correct
3 Correct 13 ms 1628 KB Output is correct
4 Correct 16 ms 1624 KB Output is correct
5 Correct 13 ms 1628 KB Output is correct
6 Correct 13 ms 1628 KB Output is correct
7 Correct 14 ms 1624 KB Output is correct
8 Correct 13 ms 1784 KB Output is correct
9 Correct 20 ms 1880 KB Output is correct
10 Correct 24 ms 2016 KB Output is correct
11 Correct 21 ms 1628 KB Output is correct
12 Correct 46 ms 3108 KB Output is correct
13 Correct 59 ms 4712 KB Output is correct
14 Correct 83 ms 6228 KB Output is correct
15 Correct 103 ms 7688 KB Output is correct
16 Correct 123 ms 9488 KB Output is correct
17 Correct 147 ms 10580 KB Output is correct
18 Correct 176 ms 12112 KB Output is correct
19 Correct 199 ms 13908 KB Output is correct
20 Correct 179 ms 10576 KB Output is correct