# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
658646 | stephenc | Job Scheduling (CEOI12_jobs) | C++17 | 414 ms | 17328 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll=long long;
bool validate(vector<pair<int,int>>& requests, ll num_machines, int day_num, int max_delay) {
int requests_today=0;
int cur_day=1;
// cout<<1<<": ";
for (auto& p : requests) {
// cout<<"("<<p.first<<", "<<p.second<<") ";
requests_today++;
if (requests_today>=num_machines) {
cur_day++;
requests_today=0;
// cout<<"\n"<<cur_day<<": ";
}
if (cur_day-p.first>max_delay||cur_day>day_num) return false;
}
return true;
}
int main() {
int n, d, m;
cin>>n>>d>>m;
vector<pair<int,int>> requests;
for (int i=1; i<=m; ++i) {
int r;
cin>>r;
requests.push_back({r, i});
}
sort(begin(requests), end(requests));
// for (auto& p : requests) {
// cout<<p.first<<" "<<p.second<<"\n";
// }
// ll mid=1;
// cout<<validate(requests, mid, n, d)<<"\n";
ll lo=1, hi=1e6, sol=1e6; //number of machines
while (lo<=hi) {
ll mid=lo+(hi-lo)/2; //number of machines
if (validate(requests, mid, n, d)) {
sol=min(sol, mid);
hi=mid-1;
} else {
lo=mid+1;
}
}
cout<<sol<<"\n";
int request_num=0;
for (int i=0; i<n; ++i) {
for (int j=0; j<sol; ++j) {
if (request_num<m) cout<<requests[request_num].second<<" ";
request_num++;
}
cout<<0<<"\n";
}
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
1: (1, 1) (1, 5)
2: (2, 2) (2, 4)
3: (2, 9) (3, 6)
4: (3, 10) (4, 3)
5: (4, 12) (5, 7)
6: (6, 8) (6, 11)
7: 1
num_machines = 2
1 1 1
1 1 5
2 2 2
2 2 4
3 2 9
3 3 6
4 3 10
4 4 3
5 4 12
5 5 7
6 6 8
6 6 11
binary search through number of machines needed
validate if constraints are satisfied
*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |