Submission #639925

#TimeUsernameProblemLanguageResultExecution timeMemory
639925ghostwriterJob Scheduling (CEOI12_jobs)C++14
55 / 100
230 ms17216 KiB
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Cay ngay cay dem nhung deo duoc cong nhan
*/
const int M = 1e6 + 1;
int n, d, m;
pi t[M];
bool check(int x) {
	int timer = 0;
	FOR(i, 1, m) {
		++timer;
		int j = min(i + x - 1, m);
		FOR(z, i, j)
			if (timer > t[z].st + d)
				return 0;
		i = j;
	}
	return 1;
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // freopen(file".inp", "r", stdin);
    // freopen(file".out", "w", stdout);
    cin >> n >> d >> m;
    FOR(i, 1, m) {
    	cin >> t[i].st;
    	t[i].nd = i;
    }
    sort(t + 1, t + 1 + m);
    int l = 1, r = m, ans = -1;
    WHILE(l <= r) {
    	int mid = l + (r - l) / 2;
    	if (check(mid)) {
    		ans = mid;
    		r = mid - 1;
    	}
    	else l = mid + 1;
    }
    cout << ans << '\n';
    int timer = 0;
    FOR(i, 1, m) {
    	++timer;
		int j = min(i + ans - 1, m);
		FOR(z, i, j) cout << t[z].nd << ' ';
		cout << 0 << '\n';
		i = j;
    }
    FOR(i, timer + 1, n) cout << 0 << '\n';
    return 0;
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
*/

Compilation message (stderr)

jobs.cpp: In function 'bool check(int)':
jobs.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
jobs.cpp:41:2: note: in expansion of macro 'FOR'
   41 |  FOR(i, 1, m) {
      |  ^~~
jobs.cpp:24:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
jobs.cpp:44:3: note: in expansion of macro 'FOR'
   44 |   FOR(z, i, j)
      |   ^~~
jobs.cpp: In function 'int main()':
jobs.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
jobs.cpp:56:5: note: in expansion of macro 'FOR'
   56 |     FOR(i, 1, m) {
      |     ^~~
jobs.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
jobs.cpp:72:5: note: in expansion of macro 'FOR'
   72 |     FOR(i, 1, m) {
      |     ^~~
jobs.cpp:24:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
jobs.cpp:75:3: note: in expansion of macro 'FOR'
   75 |   FOR(z, i, j) cout << t[z].nd << ' ';
      |   ^~~
jobs.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
jobs.cpp:79:5: note: in expansion of macro 'FOR'
   79 |     FOR(i, timer + 1, n) cout << 0 << '\n';
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...