답안 #384255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384255 2021-04-01T01:30:39 Z MalachiN Job Scheduling (CEOI12_jobs) C++14
100 / 100
621 ms 17132 KB
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
int N, D, M;
int jobs[1000001];
vector<int> byngggumb[100001];
bool test(int x){
    int tracker = 0;
    for (int n = 1; n <= N; n++){
        int itter = tracker;
        for (int c = itter; c < itter+x; c++){
            if (tracker < M){
                if (jobs[tracker] <= n){
                    if (jobs[tracker]+D < n){
                        return false;
                    }
                    tracker++;
                }
                else {
                    break;
                }
                
            }
            else {
                return true;
            }
  
        }
    }
    return true;
}
int main(int argc, const char * argv[]) {
    //ifstream cin ("file.in"); ofstream cout ("file.out");
 
    cin >> N >> D >> M;
    for (int m = 0; m < M; m++){
        int z;
        cin >> z;
        byngggumb[z].push_back(m+1);
        jobs[m] = z;
    }
    sort(jobs, jobs + M);
    int low = 1;
    int high = 1000000000;
    while (low < high){
        int middle = (low + high)/2;
     //   cout << "High: " << high << " Low: " << low << " Middle: " << middle << endl;
        if (test(middle)){
            if (middle == 1){
       //         cout << "ONE";
            }
            high = middle;
        }
        else {
            low = middle + 1;
        }
        
            
    }
    
    int tracker = 0;
    cout << low << endl;
    for (int n = 1; n <= N; n++){
        int itter = tracker;
        bool exit = false;
        for (int c = itter; c < itter+low; c++){
            if (tracker < M){
                if (jobs[tracker] <= n){
                    cout << byngggumb[jobs[tracker]][byngggumb[jobs[tracker]].size()-1] << " ";
                    byngggumb[jobs[tracker]].pop_back();
                    tracker++;
                }
                else {
                    break;
                }
                
            }
            else {
                exit = true;
                break;
            }
  
        }
        cout << "0" << endl;
    }

}

Compilation message

jobs.cpp: In function 'int main(int, const char**)':
jobs.cpp:67:14: warning: variable 'exit' set but not used [-Wunused-but-set-variable]
   67 |         bool exit = false;
      |              ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 4196 KB Output is correct
2 Correct 61 ms 4196 KB Output is correct
3 Correct 62 ms 4232 KB Output is correct
4 Correct 61 ms 4196 KB Output is correct
5 Correct 67 ms 4196 KB Output is correct
6 Correct 60 ms 4196 KB Output is correct
7 Correct 61 ms 4196 KB Output is correct
8 Correct 60 ms 4196 KB Output is correct
9 Correct 253 ms 4588 KB Output is correct
10 Correct 260 ms 4716 KB Output is correct
11 Correct 50 ms 4204 KB Output is correct
12 Correct 97 ms 5868 KB Output is correct
13 Correct 143 ms 8172 KB Output is correct
14 Correct 237 ms 9580 KB Output is correct
15 Correct 232 ms 11116 KB Output is correct
16 Correct 339 ms 13292 KB Output is correct
17 Correct 407 ms 15488 KB Output is correct
18 Correct 397 ms 16108 KB Output is correct
19 Correct 621 ms 17132 KB Output is correct
20 Correct 402 ms 15340 KB Output is correct