제출 #562737

#제출 시각아이디문제언어결과실행 시간메모리
562737MridulJob Scheduling (CEOI12_jobs)C++14
0 / 100
570 ms37788 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define inf 1e18
#define ff first
#define ss second
#define mod 1000000007

bool helper(vector<pair<int,int>> &jobs,vector<vector<int>> &ans,int n, int d, int m, int mid){

    /*
        Out here we need to count all the jobs that have frequency above
        0 and need to be processed with following mid machines.
    */

    auto temp = jobs;
    vector<int> machines(mid, 0);
    // Initially all the machines are unoccupied.
    vector<int> days(m+1,0);
    // we also need to maintain the no of days it took the job to complete.

    int i = 1;
    int j = 0;
    int count = 0;

    vector<vector<int>> res;
    while(i<=m){

        count++;
        vector<int> t;
        while(i<=m&&j<mid){


            if(temp[i].first>0){


                //reduce the frequency
                temp[i].first--;
                t.push_back(jobs[i].second);

                //update the counter of intital date
                //if not updated
                if(days[temp[i].second]==0){
                    days[temp[i].second]=count;
                }
                //update the res vector

                // if frequency ends, then update the total days
                if(temp[i].first==0){
                    if(count-days[temp[i].second]>d)
                        return false;
                    else
                        days[temp[i].second] = count - days[temp[i].second];
                    i++;
                }

                j++;

            }else{
                i++;
            }

        }
        t.push_back(0);
        res.push_back(t);
        j=j%mid;
    }

    
    if(count>n)
        return false;

    ans = res;

    return true;
}

void binarySearch(vector<pair<int,int>> &jobs, vector<vector<int>> res,int n, int d, int m){

    /*
        We need to find the minimum number of machines such
        that no job has to wait for more than 'd' days 
        since its commencement.
    */

    int l = 1;
    int r = m;
    int ans;

    while(l<=r){
        int mid = l + (r-l)/2;
        bool check = helper(jobs,res,n,d,m,mid);
        if(check){
            ans = mid;

            r = mid-1;
        }else{
            l = mid+1;
        }
    }

    cout<<ans<<endl;
    
    while(res.size()<n){
        res.push_back({0});
    }

    

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

}



void solve(){
    int n,d,m;
    cin>>n>>d>>m;


    vector<pair<int,int>> jobs(m+1);
    vector<vector<int>> ans;
    for(int i = 0;i<m;i++){
        ll x;
        cin>>x;
        jobs[x].first++;
        jobs[x].second = x;
    }

    sort(jobs.begin(),jobs.end());
    binarySearch(jobs,ans, n, d, m);
    
}  


int main()
{   
   
    int t=1;
    //cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;

}

컴파일 시 표준 에러 (stderr) 메시지

jobs.cpp: In function 'void binarySearch(std::vector<std::pair<int, int> >&, std::vector<std::vector<int> >, int, int, int)':
jobs.cpp:105:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  105 |     while(res.size()<n){
      |           ~~~~~~~~~~^~
jobs.cpp:111:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     for(int i = 0;i<res.size();i++){
      |                   ~^~~~~~~~~~~
jobs.cpp:112:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |         for(int j = 0;j<res[i].size();j++){
      |                       ~^~~~~~~~~~~~~~
jobs.cpp:103:11: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
  103 |     cout<<ans<<endl;
      |           ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...