제출 #1353465

#제출 시각아이디문제언어결과실행 시간메모리
1353465Zone_zoneeJob Scheduling (CEOI12_jobs)C++20
100 / 100
64 ms19024 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10, M = 1e6+10;

int n, k, m;
vector<int> a[N];
vector<int> ans[N];
int day[M];
bool chk(int mid){
    int cur = 1, mac = 1;
    for(int i = 1; i <= n; ++i){
        if(cur < i) cur = i, mac = 1;
        for(int x : a[i]){
            if(cur > i+k) return false;
            if(mac == mid) cur++, mac = 1;
            else mac++;
        }
    }
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k >> m;
    for(int i = 1; i <= m; ++i){
        int x; cin >> x;
        a[x].push_back(i);
    }
    int l = 1, r = M;
    while(l < r){
        int mid = (l+r)>>1;
        if(chk(mid)) r = mid;
        else l = mid+1;
    }
    cout << l << '\n';
    int cur = 1, mac = 1;
    for(int i = 1; i <= n; ++i){
        if(cur < i) cur = i, mac = 1;
        for(int x : a[i]){
            day[x] = cur;
            if(mac == l) cur++, mac = 1;
            else mac++;
        }
    }
    for(int i = 1; i <= m; ++i){
        ans[day[i]].push_back(i);
    }
    for(int i = 1; i <= n; ++i){
        for(int x : ans[i]) cout << x << ' ';
        cout << 0 << '\n';
    }
    cout << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...