Submission #710750

#TimeUsernameProblemLanguageResultExecution timeMemory
710750Spade1Job Scheduling (CEOI12_jobs)C++14
100 / 100
162 ms13628 KiB
#include<bits/stdc++.h>
#define pii pair<int, int>
#define ll long long
#define INF 2e9
#define nd second
#define st first
#define pb push_back
using namespace std;

const int N = 1e5 + 10;
int cnt[N], idx[N];
vector<int> W[N];

void solve() {
    int n, d, m; cin >> n >> d >> m;
    for (int i = 1; i <= m; ++i) {
        int j; cin >> j;
        cnt[j]++;
        W[j].pb(i);
    }

    int l = 1, r = 1e6;
    while (l < r) {
        int mid = (l+r)/2;
        bool no = 0;
        deque<pii> dq;
        for (int i = 1; i <= n; ++i) {
            dq.push_back({cnt[i], i});
            int cur = 0;
            while (!dq.empty() && cur < mid) {
                if (i - dq.front().nd > d) {
                    no = 1;
                    break;
                }
                if (dq.front().st + cur > mid) {
                    auto [w, i] = dq.front();
                    dq.pop_front();
                    dq.push_front({w-mid+cur, i});
                    cur = mid;
                }
                else {
                    cur += dq.front().st;
                    dq.pop_front();
                }
            }
            if (no) break;
        }
        if (no) l = mid+1;
        else r = mid;
    }
    cout << l << '\n';
    deque<pii> dq;
    for (int i = 1; i <= n; ++i) {
        dq.push_back({cnt[i], i});
        int cur = 0;
        while (!dq.empty() && cur < l) {
            if (dq.front().st + cur > l) {
                auto [w, i] = dq.front();
                dq.pop_front();
                dq.push_front({w-l+cur, i});
                for (int j = 0; j < l-cur; ++j) {
                    cout << W[i][idx[i]++] << " ";
                }
                cur = l;
            }
            else {
                auto [w, i] = dq.front();
                for (int j = 0; j < w; ++j) {
                    cout << W[i][idx[i]++] << " ";
                }
                cur += dq.front().st;
                dq.pop_front();
            }
        }
        cout << 0 << '\n';
    }
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	int t = 1;
//    cin >> t;
	while (t--) {
		solve();
	}

    return 0;
}

Compilation message (stderr)

jobs.cpp: In function 'void solve()':
jobs.cpp:36:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   36 |                     auto [w, i] = dq.front();
      |                          ^
jobs.cpp:58:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   58 |                 auto [w, i] = dq.front();
      |                      ^
jobs.cpp:67:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   67 |                 auto [w, i] = dq.front();
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...