# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
928062 | megaminion | Job Scheduling (CEOI12_jobs) | C++17 | 175 ms | 27248 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define ins insert
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define endl '\n'
using namespace std;
const int M = 1e6;
const int N = 1e5;
int n, d, m;
int a[M], mp[N+1];
vector<int> v[N+1];
vector<int> p[N+1];
bool ok(int x, bool flag)
{
bool ret = true;
deque<int> dq;
for(int i = 1; i <= n; ++i)
{
if(flag)
v[i].clear();
for(int j = 0; j < mp[i]; ++j)
{
dq.pb(i);
}
for(int j = 0; j < x; ++j)
{
if(dq.empty()) break;
ret &= i - dq[0] <= d;
if(flag)
{
v[i].pb(p[dq[0]].back());
p[dq[0]].pop_back();
}
dq.pop_front();
}
}
return ret;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n>>d>>m;
for(int i = 0; i < m; ++i)
{
cin>>a[i];
mp[a[i]]++;
p[a[i]].pb(i+1);
}
int L = 1, R = 1e6, mid;
while(L < R)
{
mid = L + (R - L) / 2;
if(ok(mid, false))
{
R = mid;
}
else
{
L = mid+1;
}
}
assert(ok(L, true));
cout<<L<<endl;
for(int i = 1; i <= n; ++i)
{
for(int j = 0; j < sz(v[i]); ++j)
{
cout<<v[i][j];
if(j + 1 != sz(v[i])) cout<<" ";
else cout<<" 0";
}
if(v[i].empty())
{
cout<<"0";
}
if(i != n) cout<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |