# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
545596 | aidan0626 | Job Scheduling (CEOI12_jobs) | C++14 | 527 ms | 29752 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#define mp make_pair
using pi=pair<int, int>;
using vi=vector<int>;
int N, D, M;
pair<bool, vector<vi>> isFeasible(const vector<pi> &jobs, int machineCount) {
vector<vi> schedule(N);
int reqNum=0;
for (int day=1; day<=N; day++) {
for (int j=0; j<machineCount; j++) {
if (jobs[reqNum].first>day)
break;
if (jobs[reqNum].first+D>=day)
schedule[day+1].push_back(jobs[reqNum++].second);
else
return mp(false, schedule);
if (reqNum==M)
return mp(true, schedule);
}
}
return mp(false, schedule);
}
int main() {
cin.tie(0)->sync_with_stdio(false);
cin >> N >> D >> M;
vector<pi> jobs(M);
for (int i=0; i<M; i++) {
int day;
cin >> day;
jobs[i]=mp(day, i+1);
}
sort(all(jobs));
vector<vi> result;
int l=1, r=M;
while (l<r) {
int machineNum=(l+r)/2;
pair<bool, vector<vi>> curResult=isFeasible(jobs, machineNum);
if (curResult.first) {
r=machineNum;
result=curResult.second;
}
else
l=machineNum+1;
}
cout << l << endl;
for (int i=0; i<N; i++) {
for (int &idx : result[i])
cout << idx << " ";
cout << 0 << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |