Submission #638237

# Submission time Handle Problem Language Result Execution time Memory
638237 2022-09-05T05:02:08 Z bonk Job Scheduling (CEOI12_jobs) C++14
100 / 100
247 ms 19912 KB
#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, d, m; cin >> n >> d >> m;
    vector<int>freq[n + 1];

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

    int l = 1, r = m;
    int ans = m;
    
    while(l <= r){
        int mid = (l + r)/2;
        queue<int>q;
        bool ok = true;

        for(int i = 1; i <= n; i++){
            if(!ok) break;
            for(int j = 0; j < freq[i].size(); j++) q.push(i);
            for(int j = 0; j < mid; j++){
                if(q.empty()) break;
                if(q.front() + d < i){
                    ok = false;
                    break;
                }
                q.pop();
            }
        }

        ok &= (q.empty());

        if(ok){
            ans = mid;
            r = mid - 1;
        } else{
            l = mid + 1;
        }
    }

    queue<int>q;
    vector<int>sv[n + 1];

    for(int i = 1; i <= n; i++){
        for(auto &x: freq[i]) q.push(x);
        for(int j = 0; j < ans; j++){
            if(q.empty()) break;
            sv[i].push_back(q.front()); q.pop();
        }
    }

    cout << ans << '\n';
    for(int i = 1; i <= n; i++){
        for(auto &x: sv[i]) cout << x << " ";
        cout << 0;
        if(i < n) cout << '\n';
    }

    return 0;
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:25:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |             for(int j = 0; j < freq[i].size(); j++) q.push(i);
      |                            ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 25 ms 2764 KB Output is correct
2 Correct 26 ms 2788 KB Output is correct
3 Correct 26 ms 2776 KB Output is correct
4 Correct 29 ms 2760 KB Output is correct
5 Correct 29 ms 2764 KB Output is correct
6 Correct 28 ms 2772 KB Output is correct
7 Correct 26 ms 2760 KB Output is correct
8 Correct 25 ms 2776 KB Output is correct
9 Correct 40 ms 6868 KB Output is correct
10 Correct 39 ms 6808 KB Output is correct
11 Correct 26 ms 1940 KB Output is correct
12 Correct 53 ms 3660 KB Output is correct
13 Correct 76 ms 6532 KB Output is correct
14 Correct 118 ms 8808 KB Output is correct
15 Correct 124 ms 8528 KB Output is correct
16 Correct 163 ms 11196 KB Output is correct
17 Correct 199 ms 15688 KB Output is correct
18 Correct 217 ms 14864 KB Output is correct
19 Correct 247 ms 19912 KB Output is correct
20 Correct 205 ms 15888 KB Output is correct