Submission #361279

# Submission time Handle Problem Language Result Execution time Memory
361279 2021-01-29T07:07:21 Z parsabahrami Job Scheduling (CEOI12_jobs) C++17
70 / 100
349 ms 44780 KB
// Call my Name and Save me from The Dark
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second

const int N = 1e6 + 10;
int n, D, m; pii A[N]; vector<int> vec[N];

int check(int x) {
    for (int i = 1, ptr = 0, cnt = 0; i <= n && ptr < m; i++) {
        if (i - A[ptr + 1].F > D) return 0;
        cnt = 0;
        while (ptr < m && A[ptr + 1].F <= i && cnt < x) ptr++, cnt++;
    }
    return 1;
}

void make(int x) {
    for (int i = 1, ptr = 0, cnt = 0; i <= n && ptr < m; i++) {
        assert(i - A[ptr + 1].F <= D); 
        cnt = 0;
        while (ptr < m && A[ptr + 1].F <= i && cnt < x) {
            vec[i].push_back(A[ptr + 1].S);
            ptr++, cnt++;
        }
    }
}

int main() {
    scanf("%d%d%d", &n, &D, &m);
    for (int i = 1; i <= m; i++) scanf("%d", &A[i].F), A[i].S = i;
    sort(A + 1, A + m + 1);
    int l = 0, r = m + 1;
    while (r - l > 1) {
        int mid = (l + r) >> 1;
        if (check(mid)) r = mid;
        else l = mid;
    }
    printf("%d\n", r);
    make(r);
    for (int i = 1; i <= n; i++) {
        for (int j : vec[i]) {
            printf("%d ", j);
        }
        printf("0\n");
    }
    return 0;
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |     scanf("%d%d%d", &n, &D, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:38:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |     for (int i = 1; i <= m; i++) scanf("%d", &A[i].F), A[i].S = i;
      |                                  ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 41 ms 25708 KB Output is correct
2 Correct 46 ms 25708 KB Output is correct
3 Correct 47 ms 25708 KB Output is correct
4 Correct 41 ms 25836 KB Output is correct
5 Correct 41 ms 25708 KB Output is correct
6 Correct 41 ms 25708 KB Output is correct
7 Correct 41 ms 25708 KB Output is correct
8 Correct 42 ms 25836 KB Output is correct
9 Correct 54 ms 25964 KB Output is correct
10 Correct 55 ms 25868 KB Output is correct
11 Correct 50 ms 25708 KB Output is correct
12 Correct 87 ms 27756 KB Output is correct
13 Correct 124 ms 30316 KB Output is correct
14 Correct 166 ms 32364 KB Output is correct
15 Runtime error 204 ms 33260 KB Memory limit exceeded
16 Runtime error 247 ms 35948 KB Memory limit exceeded
17 Runtime error 281 ms 42476 KB Memory limit exceeded
18 Runtime error 322 ms 42860 KB Memory limit exceeded
19 Runtime error 349 ms 44780 KB Memory limit exceeded
20 Runtime error 296 ms 42732 KB Memory limit exceeded