제출 #1134545

#제출 시각아이디문제언어결과실행 시간메모리
1134545amin5555Job Scheduling (CEOI12_jobs)C++20
100 / 100
263 ms26320 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> requests; int n, d, m; pair<vector<vector<int>>, bool> valid(int num_machines){ vector<vector<int>> schedule(n); int reqNum = 0; for(int day = 0; day < n; day++){ for(int i=0; i < num_machines; i++){ if(requests[reqNum].first > day + 1){ break; } if(requests[reqNum].first + d < day + 1) return make_pair(schedule, false); schedule[day].push_back(requests[reqNum++].second); if(reqNum == m) return make_pair(schedule, true); } } return make_pair(schedule, false); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> d >> m; requests.resize(m); for(int i=0; i<m; i++){ cin >> requests[i].first; requests[i].second = i; } sort(requests.begin(), requests.end()); vector<vector<int>> schedule; int lo = 1, hi = m; while(lo < hi){ int mid = lo + (hi - lo) / 2; pair<vector<vector<int>>, bool> res = valid(mid); if(res.second){ hi = mid; schedule = res.first; } else { lo = mid + 1; } } cout << hi << '\n'; for(auto day: schedule){ for(int job: day){ cout << job + 1 << ' '; } cout << "0\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...