제출 #225792

#제출 시각아이디문제언어결과실행 시간메모리
225792Andrei_CotorJob Scheduling (CEOI12_jobs)C++11
100 / 100
331 ms27000 KiB
#include<iostream>
#include<algorithm>
#include<deque>
#include<vector>

using namespace std;

vector<int> Jobs[100005];
vector<int> Rez[100005];
int Day[1000005];
int n,d;

bool possible(int capacity)
{
    deque<int> Pending;
    for(int i=1; i<=n; i++)
    {
        Rez[i].clear();
        for(auto job:Jobs[i])
            Pending.push_back(job);

        for(int j=1; j<=capacity; j++)
        {
            if(Pending.empty())
                break;

            if(i-Day[Pending.front()]>d)
                return 0;

            Rez[i].push_back(Pending.front());
            Pending.pop_front();
        }
    }

    if(!Pending.empty())
        return 0;
    return 1;
}

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

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

    int rez=0;
    for(int i=19; i>=0; i--)
    {
        if(!possible(rez+(1<<i)))
            rez+=(1<<i);
    }

    rez++;
    cout<<rez<<"\n";

    possible(rez);
    for(int i=1; i<=n; i++)
    {
        for(auto task:Rez[i])
            cout<<task<<" ";
        cout<<"0\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...