답안 #623911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
623911 2022-08-06T23:38:23 Z afatpotato Job Scheduling (CEOI12_jobs) C++14
100 / 100
385 ms 19876 KB
#include <bits/stdc++.h>

using namespace std;

bool solve(int x);


int n, d, m;
vector<vector<int> > request;

int main() {
    cin >> n >> d >> m;
    request.resize(n+1);

    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        request[a].push_back(i+1);
    }
    int low = 1;
    int high = m;
    int ans = 0;
    while (low < high) {
        int mid = (low + high) / 2;
        if (solve(mid)) {
            high = mid;
            ans = mid;
        } else {
            low = mid + 1;
        }
    }
    cout << ans << endl;
    vector<vector<int> > output(n+1);
    queue<int> q;
    int idx = 1;
    for (int i = 1; i < n+1; i++) {
        for (int j = 0; j < request[i].size(); j++) {
            q.push(request[i][j]);
        }
        for (int j = 0; j < ans; j++) {
            if (q.empty()) {
                break;
            }
            output[idx].push_back(q.front());
            q.pop();
        }
        idx++;
    }
    for (int i = 1; i < n+1; i++) {
        for (int j = 0; j < output[i].size(); j++) {
            cout << output[i][j] << " ";
        }
        cout << 0;
        cout << endl;
    }
    // cout << solve(3) << endl;
}

bool solve(int x) {
    vector<int> cur(n+1);
    int idx = 1;
    for (int i = 1; i < n+1; i++) {
        cur[i] = request[i].size();
        int num = x;
        // cout << idx << " " << i << " ";
        while (idx <= i && num != 0) {
            // cout << cur[idx] << endl;
            if (cur[idx] == 0) {
                idx++;
            } else if (num < cur[idx]) {
                cur[idx] -= num;
                num = 0;
            } else if (num == cur[idx]) {
                cur[idx] -= num; 
                idx++;
                num = 0;
            } else {
                num -= cur[idx];
                cur[idx] = 0;
                idx++;
            }
        }
        if (i - idx >= d) {
            return false;
        }
    }
    while (idx < n+1) {
        if (cur[idx] == 0) {
            idx++;
        } else {
            return false;
        }
    }
    return true;
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:37:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for (int j = 0; j < request[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~
jobs.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (int j = 0; j < output[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 2832 KB Output is correct
2 Correct 39 ms 2804 KB Output is correct
3 Correct 36 ms 2780 KB Output is correct
4 Correct 37 ms 2844 KB Output is correct
5 Correct 37 ms 2840 KB Output is correct
6 Correct 37 ms 2844 KB Output is correct
7 Correct 38 ms 2732 KB Output is correct
8 Correct 37 ms 2756 KB Output is correct
9 Correct 150 ms 7004 KB Output is correct
10 Correct 153 ms 6980 KB Output is correct
11 Correct 36 ms 1996 KB Output is correct
12 Correct 57 ms 3648 KB Output is correct
13 Correct 86 ms 6492 KB Output is correct
14 Correct 155 ms 8884 KB Output is correct
15 Correct 140 ms 8488 KB Output is correct
16 Correct 207 ms 11176 KB Output is correct
17 Correct 240 ms 15932 KB Output is correct
18 Correct 235 ms 14756 KB Output is correct
19 Correct 385 ms 19876 KB Output is correct
20 Correct 246 ms 15852 KB Output is correct