# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
677974 | KenHuang | Job Scheduling (CEOI12_jobs) | C++14 | 569 ms | 45748 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, D, M;
vector<pair<ll,ll>>v; // {the day, the i +1 value}
ll ans = 1e6;
vector<vector<ll>>ans_vec;
pair<bool, vector<vector<ll>>>check_valid(ll mid) {
ll current_request = 0;
vector<vector<ll>>the_days(N);
//we can simulate the days from 1 to N
for (ll day = 1; day <= N; day++){
//we can only process mid requests before we have to move onto the next day
for (ll i = 0; i < mid; i++){
//if the delay + Mi is less than the current day then we can't do nothing
if (v[current_request].first + D < day){
return {false, the_days};
}
if (v[current_request].first > day) break; //we can go to the next time cus we can't process it at the current time
the_days[day-1].push_back(v[current_request].second);
current_request++;
if (current_request == M){ //if all the requests are processed then we gucci
return {true, the_days};
}
}
}
//not all requests can be processed within the N given days
return {false, the_days};
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> N >> D >> M;
for (ll i = 0; i < M; i++){
ll num; cin >> num;
v.push_back({num, i+1});
}
sort(v.begin(), v.end());
ll lo = 1;
ll hi = M;
while (lo <= hi){
ll mid = lo + (hi-lo)/2;
//check if mid works and also get the vector output if mid does work
pair<bool, vector<vector<ll>>>current_results = check_valid(mid);
if (current_results.first){
ans = min(ans, mid);
ans_vec = current_results.second;
hi = mid-1;
} else{
lo = mid+1;
}
}
cout << ans << endl;
for (auto days : ans_vec){
for (auto day : days){
cout << day << " ";
}
cout << 0 << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |