답안 #639945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639945 2022-09-12T18:57:02 Z ghostwriter Job Scheduling (CEOI12_jobs) C++14
100 / 100
211 ms 17012 KB
#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
*/

Compilation message

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) {
      |   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 4436 KB Output is correct
2 Correct 22 ms 4388 KB Output is correct
3 Correct 22 ms 4404 KB Output is correct
4 Correct 22 ms 4408 KB Output is correct
5 Correct 22 ms 4436 KB Output is correct
6 Correct 21 ms 4404 KB Output is correct
7 Correct 23 ms 4424 KB Output is correct
8 Correct 22 ms 4408 KB Output is correct
9 Correct 30 ms 4492 KB Output is correct
10 Correct 32 ms 4460 KB Output is correct
11 Correct 22 ms 4180 KB Output is correct
12 Correct 49 ms 5708 KB Output is correct
13 Correct 67 ms 7988 KB Output is correct
14 Correct 110 ms 9796 KB Output is correct
15 Correct 109 ms 11052 KB Output is correct
16 Correct 145 ms 13116 KB Output is correct
17 Correct 182 ms 15436 KB Output is correct
18 Correct 187 ms 15740 KB Output is correct
19 Correct 211 ms 17012 KB Output is correct
20 Correct 178 ms 15428 KB Output is correct