Submission #480496

#TimeUsernameProblemLanguageResultExecution timeMemory
480496imaginary_unitJob Scheduling (CEOI12_jobs)C++17
22 / 100
753 ms16572 KiB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;

int n, d, m, a[1'000'000];

bool ok(int mch)
{
    priority_queue<int, vector<int>, greater<int> > pq;
    for(int i=0; i<mch; i++){
        pq.push(1);
    }
    for(int i=0; i<m; i++){
        int cur=pq.top();
        if(cur-a[i] > d){
            return 0;
        }
        pq.pop();
        pq.push(cur+1);
    }
    return 1;
}

int minMachines(int l, int r)
{
    while(r-l>1){
        int m=(l+r)/2;
        if(ok(m)){
            r=m;
        }
        else{
            l=m;
        }
    }
    return r;
}

int main()
{
    //freopen("angry.in", "r", stdin);
    //freopen("angry.out", "w", stdout);

    scanf("%d %d %d", &n, &d, &m);
    for(int i=0; i<m; i++){
        scanf("%d", &a[i]);
    }
    sort(a, a+m);
    int ans=minMachines(1, n);
    cout << ans << '\n';
    vector<int> tasks[n+1];
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
    for(int i=0; i<ans; i++){
        pq.push({1, i});
    }
    for(int i=0; i<m; i++){
        pair<int, int> cur=pq.top(); /// {day free, #}
        pq.pop();
        tasks[cur.fi].push_back(i+1);
        cur.fi++;
        pq.push(cur);
    }
    for(int i=1; i<=n; i++){
        for(int j=0; j<tasks[i].size(); j++){
            cout << tasks[i][j] << ' ';
        }
        cout << 0 << '\n';
    }
    return 0;
}

Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:65:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int j=0; j<tasks[i].size(); j++){
      |                      ~^~~~~~~~~~~~~~~~
jobs.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     scanf("%d %d %d", &n, &d, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...