제출 #666723

#제출 시각아이디문제언어결과실행 시간메모리
666723omikron123Job Scheduling (CEOI12_jobs)C++14
100 / 100
183 ms13700 KiB
// https://oj.uz/problem/view/CEOI12_jobs

#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

// n,d<=1e5, m<=1e6
int n, d, m;

struct J {
    int s, idx;
};
J jobs[1000005];

// return if x machine is enough
bool check(int x, bool print) {
    int j = 0;  // job index
    for (int i = 1; i <= n; i++) {
        // do jobs
        int cnt = 0;
        while(cnt < x && j < m && jobs[j].s <= i) {
            if (jobs[j].s + d < i)       // already expired
                return false;
            if (print)
                printf("%d ", jobs[j].idx);
            cnt++;
            j++;
        }
        if (print)
            printf("0\n");
    }
    return true;
}

inline bool cmp(J &a, J &b) {return a.s < b.s;}

inline int read() {
    int r = 0;
    bool start = false, neg = false;
    while (true) {
        char c = getchar();
        if (!start && c != '-' && (c < '0' || c > '9')) continue;
        start = true;
        if (c == '-') neg = true;
        else if (c >= '0' && c <= '9')
            r = r * 10 + c - '0';
        else
            break;
    }
    return r;
}

int main() {
    scanf("%d %d %d", &n, &d, &m);
    for (int i = 0; i < m; i++) {
        jobs[i].s = read();
        jobs[i].idx = i+1;
    }
    sort(jobs, jobs+m, cmp);

    int low = 1, high = m;
    while (low < high) {
        int mid = (low + high) / 2;
        if (check(mid, false))
            high = mid;
        else
            low = mid+1;
    }
    printf("%d\n", low);
    check(low, true);

    return 0;
}

/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4

answer is 2
*/

컴파일 시 표준 에러 (stderr) 메시지

jobs.cpp: In function 'int read()':
jobs.cpp:42:25: warning: variable 'neg' set but not used [-Wunused-but-set-variable]
   42 |     bool start = false, neg = false;
      |                         ^~~
jobs.cpp: In function 'int main()':
jobs.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%d %d %d", &n, &d, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...