Submission #1261192

#TimeUsernameProblemLanguageResultExecution timeMemory
1261192hoa208Job Scheduling (CEOI12_jobs)C++20
100 / 100
90 ms23572 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<int, int>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
#define t_test int t;cin >> t;while(t--)
const   ll mod = 1e9 + 7;
const   ll INF = 1e18;
inline  void adm(ll &x){if(x>=mod)x%=mod;else if(x<0)x+=mod;}
//--------------------------------------------------------------------

int n, d, m;
const int N = 1e5 + 10;
int a[1000003];
int cnt[N];
vector<int> vt[N], ans[N];
bool check(int x) {
    priority_queue<pa, vector<pa>, greater<pa>> q;
    FOR(i, 1, n) {
        if(cnt[i] != 0)
            q.push({i + d, cnt[i]});
        int cur = x;
        while(!q.empty()) {
            int v = q.top().fi, sl = q.top().se;
            // cout << v << ' ' << sl << '\n';
            q.pop();
            if(v < i) return false;
            if(cur - sl < 0) {
                sl -= cur;
                q.push({v, sl});
                break;
            }
            cur -= sl;
        }
    }
    if(!q.empty()) return false;
    return true;
}
void hbmt() {
    cin >> n >> d >> m;   
    FOR(i, 1, m) {
        cin >> a[i];
        cnt[a[i]]++;
        vt[a[i]].push_back(i);
    }
    int l = 1, r = m;
    int res = 0;
    while(l <= r) {
        int mid = l + r >> 1;
        if(check(mid)) {
            r = mid - 1;
            res = mid;
        }
        else l = mid + 1;
    }
    priority_queue<pa, vector<pa>, greater<pa>> q;
    FOR(i, 1, n) {
        if(cnt[i] != 0)
            q.push({i + d, cnt[i]});
        if(q.size() == 0) continue;
        int cur = res;
        while(!q.empty()) {
            int v = q.top().fi, sl = q.top().se;
            q.pop();
            if(cur - sl < 0) {
                int x = cur;
                while(!vt[v - d].empty() && x--) {
                    ans[i].push_back(vt[v - d].back());
                    vt[v - d].pop_back();
                }
                sl -= cur;
                q.push({v, sl});
                break;
            }
            int x = sl;
            while(!vt[v - d].empty() && x--) {
                ans[i].push_back(vt[v - d].back());
                vt[v - d].pop_back();
            }
            cur -= sl;
        }
    }
    cout << res << '\n';
    FOR(i, 1, n) {
        for(auto e : ans[i]) {
            cout << e << ' ';
        }
        cout << 0 << '\n';
    }
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    
    if(fopen("hbmt.inp", "r")) {
        freopen("hbmt.inp", "r", stdin);
        freopen("hbmt.out", "w", stdout);
    }
    
    // t_test 
    hbmt();
    return 0;
}

Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:102:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |         freopen("hbmt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:103:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |         freopen("hbmt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...