# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
589597 | Metal_Sonic | Job Scheduling (CEOI12_jobs) | C++17 | 409 ms | 29812 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz(x) (int)(x).size()
#define all(x) x.begin() , x.end()
void Sonic(string name = "") {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
if(sz(name)){
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
int n,d,jobs;
vector<pair<int,int>>vi;
pair<bool,vector<vector<int>>>check(int lim){
vector<vector<int>>tmp(n);
int cnt = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j < lim; j++){
if(vi[cnt].first > i)break;
if(vi[cnt].first + d >= i)
tmp[i-1].push_back(vi[cnt++].second);
else return {false,tmp};
if(cnt==jobs) return {true,tmp};
}
}
return {false,tmp};
}
void run_test_case(){
cin>>n>>d>>jobs;
for(int i = 0; i < jobs; i++){
int x;cin>>x;
vi.emplace_back(x,i+1);
}
sort(all(vi));
int l = 1, r = jobs;
vector<vector<int>>ans;
while(l<r){
int mid = l + (r-l)/2;
pair<bool,vector<vector<int>>>p = check(mid);
if(p.first){
r = mid;
ans = p.second;
}else l = mid+1;
}
cout<<l<<'\n';
for(int i = 0; i < n; i++){
for(int &it : ans[i])cout<<it<<" ";
cout<<"0\n";
}
}
int main(){
Sonic();
int T = 1;
while(T--){
run_test_case();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |