# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
531225 | ceoi_mike | Job Scheduling (CEOI12_jobs) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
int N, M, D;
bool do_schedule(vector<pi>& jobs, int n_mach, vector<vi>& schedule) {
// job id. how do we look up day. maybe job_idx
// we can look up day and job id
schedule.clear();
for (int i = 0; i <= N; i++) {
schedule.push_back(vi());
}
int job_idx = 0;
for (int day = 1; day <= N; day++) {
int mach_left = n_mach;
while (job_idx < M && jobs[job_idx].first <= day && mach_left > 0~) {
schedule[day].push_back(job_idx);
job_idx++;
mach_left--;
}
// check if any days are past deadline
for (int i = 0; i < schedule[day].size(); i++) {
int scheduled_day = jobs[schedule[day][i]].first;
int last_day_good = scheduled_day + D;
if (day > last_day_good) {
return false;
}
}
}
return true;
}
void show_schedule(vector<pi>& jobs, vector<vi>& schedule) {
for (int day = 1; day <= N; day++) {
for (int idx : schedule[day]) {
cout << jobs[idx].second << " ";
}
cout << "0" << endl;
}
}
int main()
{
cin >> N >> D >> M;
vector<pi> jobs(M);
for (int i = 0; i < M; i++) {
int sched;
cin >> sched;
jobs[i] = pi(sched, i+1);
}
sort(begin(jobs), end(jobs));
// bool do_schedule(vector<pi>& jobs, int n_mach, vector<vi>& schedule)
vector<vi> schedule;
do_schedule(jobs, 2, schedule);
show_schedule(jobs, schedule);
}