제출 #639945

#제출 시각아이디문제언어결과실행 시간메모리
639945ghostwriterJob Scheduling (CEOI12_jobs)C++14
100 / 100
211 ms17012 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 N = 1e5 + 1;
const int M = 1e6 + 1;
int n, d, m, t[M];
vi a[N];
bool check(int x) {
	deque<int> a1;
	FOR(i, 1, n) {
		EACH(j, a[i]) a1.pb(j);
		int cnt = min(x, sz(a1));
		FOR(j, 1, cnt) {
			int cur = a1.front();
			if (i > t[cur] + d) return 0;
			a1._pf();
		}
	}
	return a1.empty();
}
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];
    	a[t[i]].pb(i);
    }
    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';
    deque<int> a1;
	FOR(i, 1, n) {
		EACH(j, a[i]) a1.pb(j);
		int cnt = min(ans, sz(a1));
		FOR(j, 1, cnt) {
			int cur = a1.front();
			cout << cur << ' ';
			a1._pf();
		}
		cout << 0 << '\n';
	}
    return 0;
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
*/

컴파일 시 표준 에러 (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:42:2: note: in expansion of macro 'FOR'
   42 |  FOR(i, 1, n) {
      |  ^~~
jobs.cpp:26:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   26 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
jobs.cpp:43:3: note: in expansion of macro 'EACH'
   43 |   EACH(j, a[i]) a1.pb(j);
      |   ^~~~
jobs.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
jobs.cpp:45:3: note: in expansion of macro 'FOR'
   45 |   FOR(j, 1, cnt) {
      |   ^~~
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:58:5: note: in expansion of macro 'FOR'
   58 |     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:73:2: note: in expansion of macro 'FOR'
   73 |  FOR(i, 1, n) {
      |  ^~~
jobs.cpp:26:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   26 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
jobs.cpp:74:3: note: in expansion of macro 'EACH'
   74 |   EACH(j, a[i]) a1.pb(j);
      |   ^~~~
jobs.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
jobs.cpp:76:3: note: in expansion of macro 'FOR'
   76 |   FOR(j, 1, cnt) {
      |   ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...