Submission #1094078

# Submission time Handle Problem Language Result Execution time Memory
1094078 2024-09-28T11:44:23 Z Sunbae Job Scheduling (CEOI12_jobs) C++17
0 / 100
178 ms 19028 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> v[100000];
int a[1000000];

signed main() {
    int n, d, m;
    scanf("%d %d %d", &n, &d, &m);

    // Input reading
    for(int i = 0; i < m; ++i) {
        scanf("%d", a+i);
        v[--a[i]].push_back(i);  // Decrement a[i] before using it as an index
    }

    // Sorting the array
    sort(a, a + m);

    // Binary search
    int low = 1, high = m, ans;
    while(low <= high) {
        int mid = low + ((high - low) >> 1), ch = 1;
        for(int i = 0; i < m; ++i) {
            if(i / mid > a[i] + d) {  // Check this condition for correctness
                ch = 0;
                break;
            }
        }
        if(ch) high = mid - 1, ans = mid;
        else low = mid + 1;
    }

    // Output logic
    int cnt = 0;
    for(int i = 0, j; i < m; i = j, ++cnt) {
        for(j = i; j < m && (i / ans) == (j / ans); ++j) {
            printf("%d ", v[a[j]].back() + 1);  // Print and pop
            v[a[j]].pop_back();
        }
        puts("0");  // Add newline after each block
    }

    // Final trailing zeros
    for(int j = 0; j < n - cnt - 1; ++j) puts("0");  // Newline after each "0"
    printf("0\n");  // Final "0" with a newline
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d %d", &n, &d, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d", a+i);
      |         ~~~~~^~~~~~~~~~~
jobs.cpp:37:45: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |         for(j = i; j < m && (i / ans) == (j / ans); ++j) {
      |                                          ~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 4564 KB Expected EOLN
2 Incorrect 17 ms 4564 KB Expected EOLN
3 Incorrect 16 ms 4564 KB Expected EOLN
4 Incorrect 16 ms 4532 KB Expected EOLN
5 Incorrect 17 ms 4596 KB Expected EOLN
6 Incorrect 17 ms 4564 KB Expected EOLN
7 Incorrect 17 ms 4560 KB Expected EOLN
8 Incorrect 17 ms 4564 KB Expected EOLN
9 Incorrect 21 ms 4692 KB Expected EOLN
10 Incorrect 20 ms 4700 KB Expected EOLN
11 Incorrect 27 ms 4700 KB Expected EOLN
12 Incorrect 40 ms 6376 KB Expected EOLN
13 Incorrect 61 ms 8788 KB Expected EOLN
14 Incorrect 94 ms 10856 KB Expected EOLN
15 Incorrect 98 ms 12396 KB Expected EOLN
16 Incorrect 138 ms 14932 KB Expected EOLN
17 Incorrect 161 ms 17488 KB Expected EOLN
18 Incorrect 160 ms 17488 KB Expected EOLN
19 Incorrect 178 ms 19028 KB Expected EOLN
20 Incorrect 161 ms 17436 KB Expected EOLN