| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1088327 | metelkov | Job Scheduling (CEOI12_jobs) | C++17 | 252 ms | 23692 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 rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 998244353LL;
ll gcd(ll a, ll b) {
    if (a == 0LL) return b;
    return gcd(b % a, a);
}
vector<int> sieve(int n) {
    int sieve_size = n + 1;
    bool sieve[sieve_size];
    for (int i = 0; i < sieve_size; ++i) {
        sieve[i] = true;
    }
    for (int i = 2; i * i <= n; ++i) {
        if (sieve[i]) {
            for (int j = i * i; j <= n; j += i) {
                sieve[j] = false;
            }
        }
    }
    vector<int> ans;
    for (int i = 2; i <= n; ++i) {
        if (sieve[i]) {
            ans.push_back(i);
        }
    }
    return ans;
}
vector<ll> prime_factorization(ll n) {
    vector<ll> factors;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            while(n % i == 0) {
                n /= i;
            }
            factors.push_back(i);
        }
    }
    if (n > 1) {
        factors.push_back(n);
    }
    
    return factors;
}
ll mod_multiplication(ll a, ll b) {
    return (((a * b) % MOD + MOD) % MOD);
}
ll mod_power(ll x, ll n) {
    ll res = 1LL;
    while(n > 0LL) {
        if(n % 2LL) {
            res = mod_multiplication(res, x);
        }
        x = mod_multiplication(x, x);
        n >>= 1;
    }
    return res;
}
ll mod_inv(ll a) {
    return mod_power(a, MOD - 2LL);
}
ll nCr(ll n, ll r) {
    ll res = 1LL, div = 1LL;
    for(ll i = 1 ; i <= r ; i++) {
        res = mod_multiplication(res, n - i + 1LL);
        div = mod_multiplication(div, i);
    }
    res = mod_multiplication(res, mod_inv(div));
    return res;
}
uint64_t inv(uint64_t a, uint64_t b) {
    return 1 < a ? b - inv(b % a, a) * b / a : 1;
}
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
uint32_t next_pow2(uint32_t x) { return x == 1 ? 1 : 1 << (32 - __builtin_clz(x - 1)); }
uint32_t next_pow(uint32_t x) { return x == 1 ? 0 : 32 - __builtin_clz(x - 1); }
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, d, m;
    cin >> n >> d >> m;
    pair<int, int> a[m];
    rep(i, m) {
        
        cin >> a[i].first;
        a[i].second = i + 1;
    }   
    sort(a, a + m);
    int left = 1;
    int right = m;
    int ans = right;
    while (left <= right) {
        int mid = (right - left) / 2 + left;
        queue<int> pq;
        int available = mid;
        bool ok = true;
        
        rep(i, m) {
            int timestamp = a[i].first;
            if (available) {
                pq.push(timestamp + 1);
                --available;
                continue;
            }
            if (pq.front() > timestamp + d) {
                ok = false;
                break;
            }
            int closest = pq.front();
            pq.pop();
            pq.push(closest + 1);
        }
        if (ok) {
            right = mid - 1;
            ans = min(mid, ans);
        } else {
            left = mid + 1;
        }
    }
    vector<int> by_days[n];
    int available = ans;
    queue<int> pq;
    
    rep(i, m) {
        int timestamp = a[i].first;
        int id = a[i].second;
        if (available) {
            by_days[timestamp - 1].push_back(id);
            pq.push(timestamp + 1);
            --available;
            continue;
        }
        int closest = pq.front();
        pq.pop();
        
        by_days[closest - 1].push_back(id);
        pq.push(closest + 1);
    }
    cout << ans << '\n';
    rep(i, n) {
        for (auto j : by_days[i]) cout << j << ' ';
        cout << "0\n";
    }
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
