Submission #619760

# Submission time Handle Problem Language Result Execution time Memory
619760 2022-08-02T15:36:46 Z gmsong Job Scheduling (CEOI12_jobs) C++11
100 / 100
506 ms 27264 KB
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
typedef pair<int,int> pi;
 
vector<pi> p;
int n,d,m;
int a[1000005];
int v[100005];
vector<int> h[100005];
 
int f(int x){
    memset(v,0,sizeof(v));
    int head = 0;
    for (int i=0; i<m; i++) {
        head = p[i].first;
        while(v[head] >= x) head++;
        if(head > p[i].first + d) return 0;
        v[head]++;
    }
    return 1;
}
 
int main(){
    scanf("%d %d %d",&n,&d,&m);
    for (int i=0; i<m; i++) {
        scanf("%d",&a[i]);
        p.push_back(pi(a[i],i+1));
    }
    sort(p.begin(),p.end());
    int s = 0, e = m;
    while (s != e) {
        int m = (s+e)/2;
        if(f(m)) e = m;
        else s = m+1;
    }
    printf("%d\n",s);
    int head = 0;
    for (int i=0; i<m; i++) {
        head = max(head,p[i].first);
        while(h[head].size()>= s) head++;
        if(head > p[i].first + d) return 0;
        h[head].push_back(p[i].second);
    }
    for (int i=1; i<=n; i++) {
        for (int j=0; j<h[i].size(); j++) {
            printf("%d ",h[i][j]);
        }
        puts("0");
    }
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:44:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |         while(h[head].size()>= s) head++;
      |               ~~~~~~~~~~~~~~^~~~
jobs.cpp:49:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for (int j=0; j<h[i].size(); j++) {
      |                       ~^~~~~~~~~~~~
jobs.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d %d %d",&n,&d,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
jobs.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 5696 KB Output is correct
2 Correct 35 ms 5696 KB Output is correct
3 Correct 34 ms 5736 KB Output is correct
4 Correct 33 ms 5652 KB Output is correct
5 Correct 29 ms 5664 KB Output is correct
6 Correct 30 ms 5688 KB Output is correct
7 Correct 31 ms 5704 KB Output is correct
8 Correct 31 ms 5708 KB Output is correct
9 Correct 52 ms 5740 KB Output is correct
10 Correct 48 ms 5728 KB Output is correct
11 Correct 52 ms 5608 KB Output is correct
12 Correct 118 ms 8444 KB Output is correct
13 Correct 119 ms 11656 KB Output is correct
14 Correct 506 ms 15004 KB Output is correct
15 Correct 203 ms 16128 KB Output is correct
16 Correct 232 ms 19628 KB Output is correct
17 Correct 314 ms 24680 KB Output is correct
18 Correct 339 ms 24964 KB Output is correct
19 Correct 371 ms 27264 KB Output is correct
20 Correct 315 ms 24392 KB Output is correct