# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
571028 | elesis | Job Scheduling (CEOI12_jobs) | C++14 | 479 ms | 48808 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 fast ios_base::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
const int inf=1e11+7;
const int mod =1000000007;
int binpow(int a,int b,int m) {
a %= m;
int res = 1;
while(b>0) {
if (b&1)
{
res=res*a%m;
}
a=a*a%m;
b>>=1;
}
return res;
}
int N,M,D;
pair<bool, vector<vector <int>>> ok(vector<pii> &arr, int x)
{
vector <vector <int>> nub(N);
int job=0;
for(int i=1;i<=N;i++)
{
for(int j=0;j<x;j++)
{
if(arr[job].ff>i)
{
break;
}
if(arr[job].ff+D>=i)
{
nub[i-1].push_back(arr[job].ss);
job++;
}
else
{
return {false,nub};
}
if(job==M)
{
return {true,nub};
}
}
}
return {false,nub};
}
void solve()
{
cin>>N>>D>>M;
int ans;
vector <pii> arr(M);
for(int i=0;i<M;i++)
{
cin>>arr[i].first;
arr[i].second=i+1;
}
sort(arr.begin(),arr.end());
vector <vector <int>> res;
int lo=1,hi=M;
while(lo<hi)
{
int mid=(lo+hi)/2;
pair <bool,vector <vector <int>>> ef=ok(arr,mid);
if(ef.ff)
{
ans=mid;
res=ef.ss;
hi=mid;
}
else
{
lo=mid+1;
}
}
cout << ans << "\n";
for(int i=0;i<N;i++)
{
for(auto it:res[i])
{
cout << it << " " ;
}
cout << 0 << "\n";
}
if(ok(arr,1).ff)
{
cout << "wtf" << '\n';
}
}
signed main()
{
fast
clock_t start, end;
start = clock();
solve();
end = clock();
double time_taken=double(end-start)/double(CLOCKS_PER_SEC);
//cout << "time taken" << " " << time_taken << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |