# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1119372 | hujo | Job Scheduling (CEOI12_jobs) | C++14 | 247 ms | 31636 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdio>
using namespace std;
struct Job {
int id, start, end;
Job(int id, int start, int end) : id(id), start(start), end(end) {}
};
int N, M;
vector<Job> jobs;
bool isGood(int machines) {
queue<Job> q;
for (const Job& j : jobs) {
q.push(j);
}
for (int i = 1; i <= N; i++) {
int nleft = machines;
while (nleft > 0 && !q.empty()) {
Job top = q.front();
if (top.end < i || top.start > i) {
break;
} else {
q.pop();
nleft--;
}
}
}
return q.empty();
}
void printRes(int minMachines) {
cout << minMachines << endl;
queue<Job> q;
for (const Job& j : jobs) {
q.push(j);
}
for (int i = 1; i <= N; i++) {
int nleft = minMachines;
while (nleft > 0 && !q.empty()) {
Job top = q.front();
if (top.start > i) {
break;
} else {
cout << top.id << " ";
q.pop();
nleft--;
}
}
cout << "0\n";
}
}
int binsearchLeft(int left, int right) {
if (left > right) {
return -1;
}
int mid = left + (right - left) / 2;
if (isGood(mid)) {
int res = binsearchLeft(left, mid - 1);
return (res == -1) ? mid : res;
} else {
return binsearchLeft(mid + 1, right);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int D;
cin >> N >> D >> M;
for (int i = 1; i <= M; i++) {
int id;
cin >> id;
jobs.emplace_back(i, id, id + D);
}
sort(jobs.begin(), jobs.end(), [](const Job& j1, const Job& j2) {
return j1.end < j2.end;
});
int minMachines = binsearchLeft(0, M);
printRes(minMachines);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |