Submission #267142

# Submission time Handle Problem Language Result Execution time Memory
267142 2020-08-15T21:44:10 Z Sorting Job Scheduling (CEOI12_jobs) C++17
100 / 100
281 ms 13688 KB
#include <bits/stdc++.h>

using namespace std;

const int k_N = 1e5 + 3;
const int k_M = 1e6 + 3;

int n, d, m;
vector<int> jobs[k_N];

bool check(int mid){
    queue<int> q;
    for(int i = 1; i <= n; ++i){
        for(int x: jobs[i])
            q.push(i);

        int t = mid;
        while(t-- && !q.empty()){
            if(q.front() + d < i)
                return false;
            q.pop();
        }
    }
    return true;
}

void output(int mid){
    queue<int> q;
    for(int i = 1; i <= n; ++i){
        for(int x: jobs[i])
            q.push(x);

        int t = mid;
        while(t-- && !q.empty()){
            cout << q.front() << " ";
            q.pop();
        }
        cout << "0\n";
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> d >> m;
    for(int i = 1; i <= m; ++i){
        int x;
        cin >> x;
        jobs[x].push_back(i);
    }

    int l = 0, r = k_M;
    while(l != r){
        int mid = (l + r) >> 1;
        if(check(mid)) r = mid;
        else l = mid + 1;
    }

    cout << l << "\n";
    output(l);    
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
*/

Compilation message

jobs.cpp: In function 'bool check(int)':
jobs.cpp:14:17: warning: unused variable 'x' [-Wunused-variable]
   14 |         for(int x: jobs[i])
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 36 ms 4340 KB Output is correct
2 Correct 37 ms 4208 KB Output is correct
3 Correct 40 ms 4208 KB Output is correct
4 Correct 40 ms 4212 KB Output is correct
5 Correct 36 ms 4212 KB Output is correct
6 Correct 41 ms 4468 KB Output is correct
7 Correct 36 ms 4216 KB Output is correct
8 Correct 36 ms 4212 KB Output is correct
9 Correct 40 ms 4216 KB Output is correct
10 Correct 41 ms 4220 KB Output is correct
11 Correct 33 ms 3968 KB Output is correct
12 Correct 66 ms 5240 KB Output is correct
13 Correct 97 ms 7032 KB Output is correct
14 Correct 143 ms 8472 KB Output is correct
15 Correct 159 ms 9464 KB Output is correct
16 Correct 190 ms 11000 KB Output is correct
17 Correct 245 ms 13080 KB Output is correct
18 Correct 248 ms 12920 KB Output is correct
19 Correct 281 ms 13688 KB Output is correct
20 Correct 249 ms 13048 KB Output is correct