# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
483967 | tibiCoder | Job Scheduling (CEOI12_jobs) | C++17 | 1100 ms | 34372 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <climits>
#include <unordered_map>
#include <queue>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <bitset>
#include <iomanip>
using namespace std;
struct Event {
int time;
int arrival;
bool isEnd;
int id;
bool operator>(const Event& other) const {
if (time == other.time) {
if (isEnd == other.isEnd) {
return arrival > other.arrival;
}
return !isEnd && other.isEnd;
}
return time > other.time;
}
};
bool isPossibleForMachines(vector<int>& jobs, int maxDelay, int nOfMachines, int nOfDays, bool print) {
priority_queue<Event, vector<Event>, greater<>> nextFreeMachine;
for (int i = 0; i < jobs.size(); ++i) {
nextFreeMachine.push({jobs[i], jobs[i], false, i});
}
// vector<vector<int>> jobsPerDay;
// if (print) {
// jobsPerDay.resize(nOfDays+1);
// }
while (!nextFreeMachine.empty()) {
Event event = nextFreeMachine.top();
nextFreeMachine.pop();
while (!nextFreeMachine.empty() && nextFreeMachine.top().isEnd && nextFreeMachine.top().time==event.time) {
nextFreeMachine.pop();
++nOfMachines;
}
if (event.isEnd) {
++nOfMachines;
continue;
}
if (nOfMachines > 0) {
--nOfMachines;
if (event.time-event.arrival > maxDelay) {
return false;
}
nextFreeMachine.push({event.time+1, event.arrival, true, event.id});
// if (print) {
// jobsPerDay[event.time].emplace_back(event.id+1);
// }
}
else {
nextFreeMachine.push({event.time+1, event.arrival, false, event.id});
}
}
// if (print) {
// for (int i = 1; i < jobsPerDay.size(); ++i) {
// for (int j = 0; j < jobsPerDay[i].size(); ++j) {
// cout << jobsPerDay[i][j] << " ";
// }
// cout << "0\n";
// }
// }
if (print) {
for (int i = 0; i < nOfDays; ++i) {
cout << "0\n";
}
}
return true;
}
int main() {
int nOfDays, maxDelay, nOfJobRequests;
cin >> nOfDays >> maxDelay >> nOfJobRequests;
vector<int> jobs(nOfJobRequests);
for (int i = 0; i < nOfJobRequests; ++i) {
cin >> jobs[i];
}
int start = 1;
int end = 100000;
int low;
while (start <= end) {
int middle = start + (end-start)/2;
if (isPossibleForMachines(jobs, maxDelay, middle, nOfDays, false)) {
low = middle;
end = middle-1;
}
else {
start = middle+1;
}
}
cout << low << '\n';
isPossibleForMachines(jobs, maxDelay, low, nOfDays, true);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |