답안 #438302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
438302 2021-06-27T20:37:09 Z horsefeedapples Job Scheduling (CEOI12_jobs) C++17
100 / 100
682 ms 21660 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int MXN = 1e5+5;

int N, D, M;
vector<pair<int,int>> jobs; // day, index
vector<int> ans[MXN];

bool check(int machines){
    // Filled[i] represents how many tasks are processed on day i
    vector<int> filled(MXN, 0);
    int currDay = 0;
    for(int i=0; i<M; i++){
        currDay = max(currDay, jobs[i].first);
        while(filled[currDay]>=machines) currDay++; // try if(filled[head]>=x)
        if(currDay>jobs[i].first+D) return false;
        filled[currDay]++;
    }
    return true;
}

int firstTrue(int lo, int hi) {
	for (hi ++; lo < hi; ) {
		int mid = lo+(hi-lo)/2;
		if (check(mid)) hi = mid;
		else lo = mid+1;
	}
	return lo;
}

int main(){
    cin>>N>>D>>M;
    for(int i=0; i<M; i++){
        int x; cin>>x;
        jobs.push_back({x, i+1});
    }
    sort(jobs.begin(), jobs.end());

    int numMachines = firstTrue(0, MXN); 

    cout<<numMachines<<endl;
    
    int currDay = 0;
    for(int i=0; i<M; i++){
        currDay = max(currDay, jobs[i].first);
        while(ans[currDay].size()>=numMachines) currDay++;
        ans[currDay].push_back(jobs[i].second);
    }

    for(int i=1; i<=N; i++){
        for(int j=0; j<ans[i].size(); j++){
            cout<<ans[i][j]<<" ";
        }
        cout<<0<<endl;
    }
    return 0;
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:49:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |         while(ans[currDay].size()>=numMachines) currDay++;
      |               ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
jobs.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for(int j=0; j<ans[i].size(); j++){
      |                      ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 4940 KB Output is correct
2 Correct 62 ms 4908 KB Output is correct
3 Correct 64 ms 4920 KB Output is correct
4 Correct 62 ms 4944 KB Output is correct
5 Correct 65 ms 5104 KB Output is correct
6 Correct 65 ms 4920 KB Output is correct
7 Correct 66 ms 4908 KB Output is correct
8 Correct 63 ms 4936 KB Output is correct
9 Correct 237 ms 5076 KB Output is correct
10 Correct 218 ms 4992 KB Output is correct
11 Correct 61 ms 4832 KB Output is correct
12 Correct 121 ms 7216 KB Output is correct
13 Correct 184 ms 10200 KB Output is correct
14 Correct 264 ms 12584 KB Output is correct
15 Correct 290 ms 13428 KB Output is correct
16 Correct 379 ms 15516 KB Output is correct
17 Correct 451 ms 19456 KB Output is correct
18 Correct 487 ms 19996 KB Output is correct
19 Correct 682 ms 21660 KB Output is correct
20 Correct 446 ms 19484 KB Output is correct