답안 #98970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98970 2019-02-27T19:16:02 Z figter001 Job Scheduling (CEOI12_jobs) C++14
100 / 100
403 ms 17424 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int nax = 1e5+50;

vector<pair<int,int>> j;
vector<int> w;
int n,d,m;
queue<int> tmp;

bool can(int md){
	queue<int> q = tmp;
	int cur = 1,u = 0;
	while(q.size()){
		int v = q.front();
		if(v - d > cur){
			cur = v-d;
			u = 0;
		}
		q.pop();
		if(cur > v)return 0;
		u++;
		if(u == md){
			u = 0;
			cur++;
		}
	}
	return 1;
}

int main(){
	scanf("%d%d%d",&n,&d,&m);
	j.resize(m);
	for(int i=0;i<m;i++){
		scanf("%d",&j[i].first);
		j[i].second = i;
	}
	sort(j.begin(),j.end());
	for(int i=0;i<m;i++)
		tmp.push(j[i].first + d);
	int md,lo=1,hi=1e5,ans=1e5;
	while(lo <= hi){
		md = (lo+hi)/2;
		if(can(md)){
			hi = md-1;
			ans = md;
		}else lo = md+1;
	}
	printf("%d\n", ans);
	int u = 0,id=0;
	for(int i=0;i<n;i++){
		for(int x=0;x<ans;x++){
			if(id == m)break;
			if(j[id].first - 1 > i)break;
			printf("%d ", j[id].second + 1);
			id++;			
		}
		printf("0\n");
	}
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:54:6: warning: unused variable 'u' [-Wunused-variable]
  int u = 0,id=0;
      ^
jobs.cpp:36: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:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&j[i].first);
   ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2272 KB Output is correct
2 Correct 37 ms 2260 KB Output is correct
3 Correct 39 ms 2272 KB Output is correct
4 Correct 34 ms 2440 KB Output is correct
5 Correct 31 ms 2272 KB Output is correct
6 Correct 38 ms 2272 KB Output is correct
7 Correct 57 ms 2272 KB Output is correct
8 Correct 48 ms 2280 KB Output is correct
9 Correct 56 ms 2464 KB Output is correct
10 Correct 47 ms 2400 KB Output is correct
11 Correct 42 ms 2288 KB Output is correct
12 Correct 89 ms 4328 KB Output is correct
13 Correct 132 ms 6088 KB Output is correct
14 Correct 171 ms 8016 KB Output is correct
15 Correct 213 ms 9784 KB Output is correct
16 Correct 282 ms 11656 KB Output is correct
17 Correct 294 ms 13516 KB Output is correct
18 Correct 342 ms 15528 KB Output is correct
19 Correct 403 ms 17424 KB Output is correct
20 Correct 333 ms 13512 KB Output is correct