Submission #951625

# Submission time Handle Problem Language Result Execution time Memory
951625 2024-03-22T07:52:40 Z doducanh Job Scheduling (CEOI12_jobs) C++17
95 / 100
1000 ms 28244 KB
#include <bits/stdc++.h>

using namespace std;
#define ii pair<int,int>
#define fi first
#define se second
const int maxn=1e5+7;
vector<int>a[maxn];
vector<int>ans[maxn];
vector<int>ress[maxn];
int n,d,m;
bool check(int x)
{
    priority_queue<ii,vector<ii>,greater<ii>>q;
    for(int i=1;i<=n;i++)ans[i].clear();
    for(int i=1;i<=n;i++){

        for(int x:a[i])q.push({i,x});
        while(ans[i].size()<x&&q.size()){
            if(i-q.top().fi>d)return false;
            ans[i].push_back(q.top().se);
            q.pop();
        }
    }
    if(q.size())return false;
    for(int i=1;i<=n;i++){
        ress[i].clear();
        for(int x:ans[i])ress[i].push_back(x);
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>d>>m;
    for(int i=1;i<=m;i++){
        int x;
        cin>>x;
        a[x].push_back(i);
    }
    int l=0,r=m;
    int res=m;
    while(l<=r){
        int m=(l+r)/2;
        if(check(m)){
            res=m;
            r=m-1;
        }
        else l=m+1;
    }
    cout<<res<<"\n";
    for(int i=1;i<=n;i++){
        for(int x:ress[i])cout<<x<<" ";
        cout<<0<<"\n";
    }
    return 0;
}

Compilation message

jobs.cpp: In function 'bool check(int)':
jobs.cpp:19:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |         while(ans[i].size()<x&&q.size()){
      |               ~~~~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 142 ms 11068 KB Output is correct
2 Correct 135 ms 11072 KB Output is correct
3 Correct 138 ms 11072 KB Output is correct
4 Correct 135 ms 11024 KB Output is correct
5 Correct 137 ms 11040 KB Output is correct
6 Correct 137 ms 11016 KB Output is correct
7 Correct 136 ms 11016 KB Output is correct
8 Correct 138 ms 11012 KB Output is correct
9 Correct 114 ms 9932 KB Output is correct
10 Correct 118 ms 10160 KB Output is correct
11 Correct 70 ms 9504 KB Output is correct
12 Correct 232 ms 11944 KB Output is correct
13 Correct 273 ms 15700 KB Output is correct
14 Correct 392 ms 18752 KB Output is correct
15 Correct 399 ms 19472 KB Output is correct
16 Correct 356 ms 21920 KB Output is correct
17 Correct 540 ms 28244 KB Output is correct
18 Execution timed out 1002 ms 25588 KB Time limit exceeded
19 Correct 982 ms 26524 KB Output is correct
20 Correct 516 ms 27960 KB Output is correct