# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
977999 | vjudge1 | Job Scheduling (CEOI12_jobs) | C++17 | 400 ms | 13648 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<algorithm>
using namespace std;
int n, d, m; // available days, max delay, job count
pair<int, int> arrive[1000001]; // when the jobs come in
bool isok(int machines) {
int current = 0;
for (int i = 1; i <= n; i++) {
int machines_left = machines;
while (machines_left > 0 && current < m && arrive[current].first <= i) {
if (i - arrive[current].first > d) {
return false;
}
machines_left--;
current++;
}
}
return current == m; // can complete all jobs
}
int main() {
cin >> n >> d >> m;
for (int i = 0; i < m; i++) {
cin >> arrive[i].first;
arrive[i].second = i + 1;
}
sort(arrive, arrive + m);
int left = 1, right = m;
int ans = 1;
while (left <= right) {
int mid = (left + right) / 2; // bsearch for how many machines needed
if (isok(mid)) {
ans = mid;
right = mid - 1;
} else {
left = mid + 1;
}
}
cout << ans << endl;
int current = 0;
for (int i = 1; i <= n; i++) {
int machines_left = ans;
while (machines_left > 0 && current < m && arrive[current].first <= i) {
cout << arrive[current].second << " ";
machines_left--;
current++;
}
cout << 0 << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |