답안 #973194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973194 2024-05-01T15:49:11 Z njoop Job Scheduling (CEOI12_jobs) C++17
100 / 100
170 ms 13604 KB
#include <bits/stdc++.h>

using namespace std;

int n, d, m, in, l=0, r=1e9, mid;
vector<int> t[100010];

bool solve(int num) {
    queue<int> q;
    for(int i=1; i<=n; i++) {
        for(int j: t[i]) q.push(i);
        for(int j=1; j<=num && q.size(); j++) q.pop();
        if(q.size() && i-q.front() >= d) {
            return 0;
        }
    }
    return 1;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> d >> m;
    for(int i=1; i<=m; i++) {
        cin >> in;
        t[in].push_back(i);
    }
    while(l < r) {
        mid = (l+r)>>1;
        if(solve(mid)) {
            r = mid;
        } else {
            l = mid+1;
        }
    }
    cout << l << "\n";
    queue<int> q;
    for(int i=1; i<=n; i++) {
        for(int j: t[i]) q.push(j);
        for(int j=1; j<=l && q.size(); j++) {
            cout << q.front() << " ";
            q.pop();
        }
        cout << "0\n";
    }
    return 0;
}

Compilation message

jobs.cpp: In function 'bool solve(int)':
jobs.cpp:11:17: warning: unused variable 'j' [-Wunused-variable]
   11 |         for(int j: t[i]) q.push(i);
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 4092 KB Output is correct
2 Correct 21 ms 4060 KB Output is correct
3 Correct 25 ms 4136 KB Output is correct
4 Correct 25 ms 4048 KB Output is correct
5 Correct 24 ms 4312 KB Output is correct
6 Correct 21 ms 4060 KB Output is correct
7 Correct 20 ms 4060 KB Output is correct
8 Correct 20 ms 4144 KB Output is correct
9 Correct 29 ms 4180 KB Output is correct
10 Correct 31 ms 4176 KB Output is correct
11 Correct 20 ms 3784 KB Output is correct
12 Correct 38 ms 4944 KB Output is correct
13 Correct 57 ms 6996 KB Output is correct
14 Correct 91 ms 8276 KB Output is correct
15 Correct 117 ms 9132 KB Output is correct
16 Correct 138 ms 10856 KB Output is correct
17 Correct 168 ms 12708 KB Output is correct
18 Correct 158 ms 12744 KB Output is correct
19 Correct 170 ms 13604 KB Output is correct
20 Correct 153 ms 12628 KB Output is correct