Submission #939427

# Submission time Handle Problem Language Result Execution time Memory
939427 2024-03-06T10:55:40 Z JakobZorz Job Scheduling (CEOI12_jobs) C++17
100 / 100
258 ms 20656 KB
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
#include<random>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

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

vector<vector<int>>get(int k){
    vector<vector<int>>res(n);
    queue<pair<int,int>>q;
    for(int i=0;i<n;i++){
        for(int j:jobs[i]){
            q.push({i+d,j});
        }
        
        if(q.size()&&q.front().first<i)
            return {};
        for(int j=0;j<k&&q.size();j++){
            res[i].push_back(q.front().second);
            q.pop();
        }
    }
    
    return res;
}

void solve(){
    cin>>n>>d>>m;
    for(int i=1;i<=m;i++){
        int a;
        cin>>a;
        jobs[a-1].push_back(i);
    }
    
    int l=0,r=m;
    while(l<r-1){
        int mid=(l+r)/2;
        if(get(mid).empty()){
            l=mid;
        }else{
            r=mid;
        }
    }
    cout<<r<<"\n";
    auto res=get(r);
    for(auto i:res){
        for(auto j:i){
            cout<<j<<" ";
        }
        cout<<"0\n";
    }
}

int main(){
    ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
    //freopen("/Users/jakob/cp_testing/test.txt","r",stdin);freopen("output.out","w",stdout);
    int t=1;//cin>>t;
    while(t--)solve();
    return 0;
}

/*
 
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
 
 */

# Verdict Execution time Memory Grader output
1 Correct 25 ms 5648 KB Output is correct
2 Correct 24 ms 5384 KB Output is correct
3 Correct 25 ms 5380 KB Output is correct
4 Correct 25 ms 5644 KB Output is correct
5 Correct 28 ms 5916 KB Output is correct
6 Correct 25 ms 5644 KB Output is correct
7 Correct 25 ms 5388 KB Output is correct
8 Correct 26 ms 5604 KB Output is correct
9 Correct 33 ms 7336 KB Output is correct
10 Correct 31 ms 7576 KB Output is correct
11 Correct 24 ms 4688 KB Output is correct
12 Correct 52 ms 6852 KB Output is correct
13 Correct 75 ms 9604 KB Output is correct
14 Correct 119 ms 11780 KB Output is correct
15 Correct 115 ms 11496 KB Output is correct
16 Correct 172 ms 14884 KB Output is correct
17 Correct 209 ms 18720 KB Output is correct
18 Correct 208 ms 17700 KB Output is correct
19 Correct 252 ms 20656 KB Output is correct
20 Correct 258 ms 18716 KB Output is correct