Submission #97851

# Submission time Handle Problem Language Result Execution time Memory
97851 2019-02-18T23:31:00 Z RezwanArefin01 Job Scheduling (CEOI12_jobs) C++17
100 / 100
430 ms 20296 KB
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii; 

const int N = 1e5 + 10; 
vector<int> p[N], ans[N];
int n, d, m; 

bool check(int x) {
    for(int i = 1; i <= n; i++) ans[i].clear(); 
    for(int i = 1, idx = 1; i <= n; idx = max(idx, ++i)) {
        for(int id : p[i]) {
            if(ans[idx].size() == x) ++idx; 
            if(idx > i + d) return 0;
            ans[idx].push_back(id); 
        }
    } return 1; 
}

int main() {
    scanf("%d %d %d", &n, &d, &m); 
    for(int i = 1; i <= m; i++) {
        int x; scanf("%d", &x); 
        p[x].push_back(i);
    }
    int lo = 1, hi = m, idx; 
    while(lo <= hi) {
        int mid = lo + hi >> 1; 
        if(check(mid)) idx = mid, hi = mid - 1; 
        else lo = mid + 1; 
    }
    check(idx);
    printf("%d\n", idx); 
    for(int i = 1; i <= n; i++) {
        for(int id : ans[i]) 
            printf("%d ", id); 
        puts("0"); 
    }
}

Compilation message

jobs.cpp: In function 'bool check(int)':
jobs.cpp:16:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(ans[idx].size() == x) ++idx; 
                ~~~~~~~~~~~~~~~~^~~~
jobs.cpp: In function 'int main()':
jobs.cpp:31:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = lo + hi >> 1; 
                   ~~~^~~~
jobs.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &d, &m); 
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:26:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int x; scanf("%d", &x); 
                ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 55 ms 6640 KB Output is correct
2 Correct 39 ms 6640 KB Output is correct
3 Correct 40 ms 6640 KB Output is correct
4 Correct 41 ms 6636 KB Output is correct
5 Correct 41 ms 6648 KB Output is correct
6 Correct 37 ms 6640 KB Output is correct
7 Correct 38 ms 6640 KB Output is correct
8 Correct 36 ms 6640 KB Output is correct
9 Correct 48 ms 6880 KB Output is correct
10 Correct 70 ms 6992 KB Output is correct
11 Correct 41 ms 6648 KB Output is correct
12 Correct 86 ms 8316 KB Output is correct
13 Correct 127 ms 11140 KB Output is correct
14 Correct 197 ms 13020 KB Output is correct
15 Correct 183 ms 14072 KB Output is correct
16 Correct 316 ms 16196 KB Output is correct
17 Correct 364 ms 20196 KB Output is correct
18 Correct 430 ms 18940 KB Output is correct
19 Correct 363 ms 19704 KB Output is correct
20 Correct 384 ms 20296 KB Output is correct