Submission #230748

# Submission time Handle Problem Language Result Execution time Memory
230748 2020-05-11T14:42:33 Z Ruxandra985 Job Scheduling (CEOI12_jobs) C++14
100 / 100
344 ms 17144 KB
#include <bits/stdc++.h>

using namespace std;
int d , n , m;
pair <int,int> v[1000010];

int check (int x , int type){

    int today , days , put , i , sol = 0;

    if (type)
        printf ("%d\n",x);

    today = 0;
    days = 1;

    for (i = 1 ; i <= n ; i++){

        put = 0;

        if (days >= v[i].first && today + 1 <= x){
            today++;
            sol = max(sol , days - v[i].first);
            if (type == 1)
                printf ("%d " ,v[i].second);
            put = 1;
        }
        else if (today + 1 > x){
            today = 0;
            days++;
            if (type)
                printf ("0\n");
        }

        if (!put){
            while (days < v[i].first){
                days++;
                today = 0;
                if (type)
                    printf ("0\n");
            }
            if (type)
                printf ("%d ",v[i].second);
            today++;
            sol = max(sol , days - v[i].first);
        }


    }


    if (type){

        while (days <= m){

            printf ("0\n");
            days++;

        }

    }

    if (days <= m && sol <= d)
        return 1;
    return 0;


}

int main()
{
    FILE *fin = stdin;
    int i , st , dr , mid;
    fscanf (fin,"%d%d%d",&m,&d,&n);

    for (i = 1 ; i <= n ; i++){
        fscanf (fin,"%d",&v[i].first);
        v[i].second = i;
    }
    sort (v + 1 , v + n + 1);

    st = 1;
    dr = n;

    while (st <= dr){
        mid = (st + dr)/2;

        if (check(mid , 0))
            dr = mid - 1;
        else st = mid + 1;
    }

    check (st , 1);

    return 0;
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:74:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d%d",&m,&d,&n);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:77:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d",&v[i].first);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2048 KB Output is correct
2 Correct 30 ms 1912 KB Output is correct
3 Correct 29 ms 2048 KB Output is correct
4 Correct 30 ms 1916 KB Output is correct
5 Correct 30 ms 2040 KB Output is correct
6 Correct 30 ms 2048 KB Output is correct
7 Correct 30 ms 2048 KB Output is correct
8 Correct 30 ms 2040 KB Output is correct
9 Correct 42 ms 2168 KB Output is correct
10 Correct 43 ms 2296 KB Output is correct
11 Correct 40 ms 2040 KB Output is correct
12 Correct 77 ms 3960 KB Output is correct
13 Correct 113 ms 5752 KB Output is correct
14 Correct 156 ms 8056 KB Output is correct
15 Correct 189 ms 9592 KB Output is correct
16 Correct 236 ms 12152 KB Output is correct
17 Correct 274 ms 13944 KB Output is correct
18 Correct 301 ms 15228 KB Output is correct
19 Correct 344 ms 17144 KB Output is correct
20 Correct 279 ms 13944 KB Output is correct