// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
const int MX = 1e6+6;
const int nax = 1e5+5;
pair<int, int> in[MX];
V<int> C[nax], ans[nax];
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, D, M; cin >> N >> D >> M;
for(int i = 0; i < M; i++) {
int t; cin >> t; --t;
C[t].pb(i);
}
auto check = [&](int x, bool CREATE = 0) -> bool {
int cur = 0, len = 0;
for(int i = 0; i < N; i++) {
if (cur < len && in[cur].first <= i) return 0;
int end = i + D + 1;
for(const auto& c : C[i]) in[len++] = {end, c};
int left = x;
while(left-- && cur < len) {
if (CREATE) ans[i].push_back(in[cur].second);
cur++;
}
}
return cur == len;
};
int lo = 0, hi = M + 1;
while(lo < hi) {
int mid = (lo + hi) / 2;
if (check(mid)) hi = mid;
else lo = mid + 1;
}
check(lo, 1);
cout << lo << nl;
for(int i = 0; i < N; i++) {
for(const auto &x : ans[i]) cout << x + 1 << " ";
cout << 0 << nl;
}
cout << nl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
7380 KB |
Output is correct |
2 |
Correct |
15 ms |
7420 KB |
Output is correct |
3 |
Correct |
15 ms |
7380 KB |
Output is correct |
4 |
Correct |
17 ms |
7400 KB |
Output is correct |
5 |
Correct |
15 ms |
7380 KB |
Output is correct |
6 |
Correct |
15 ms |
7420 KB |
Output is correct |
7 |
Correct |
15 ms |
7472 KB |
Output is correct |
8 |
Correct |
15 ms |
7388 KB |
Output is correct |
9 |
Correct |
21 ms |
7716 KB |
Output is correct |
10 |
Correct |
21 ms |
7668 KB |
Output is correct |
11 |
Correct |
16 ms |
7380 KB |
Output is correct |
12 |
Correct |
29 ms |
9904 KB |
Output is correct |
13 |
Correct |
43 ms |
13504 KB |
Output is correct |
14 |
Correct |
69 ms |
16076 KB |
Output is correct |
15 |
Correct |
73 ms |
17136 KB |
Output is correct |
16 |
Correct |
99 ms |
20056 KB |
Output is correct |
17 |
Correct |
125 ms |
25480 KB |
Output is correct |
18 |
Correct |
114 ms |
25304 KB |
Output is correct |
19 |
Correct |
137 ms |
26956 KB |
Output is correct |
20 |
Correct |
125 ms |
25500 KB |
Output is correct |