#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define fi first
#define si second
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 100010;
int n, d, m;
pi arr[MAXN * 10];
vector<int> ans[MAXN];
bool good(int num, int flag) {
int j = 1;
for (int i = 1; i <= n; ++i) {
int cnt = num;
while (j <= m && cnt && arr[j].fi <= i) {
if (i - arr[j].fi > d) return false;
if (flag) ans[i].pb(arr[j].si);
++j;
--cnt;
}
}
return j >= m;
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> d >> m;
for (int i = 1; i <= m; ++i) cin >> arr[i].fi, arr[i].si = i;
sort(arr + 1, arr + 1 + m);
int lo = 0, hi = m + 1;
while (lo + 1 < hi) {
int mid = (lo + hi) >> 1;
if (good(mid, 0)) hi = mid;
else lo = mid;
}
cout << hi << '\n';
good(hi, 1);
for (int i = 1; i <= n; ++i) {
for (auto j: ans[i]) cout << j << ' ';
cout << 0 << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
4564 KB |
Output is correct |
2 |
Correct |
21 ms |
4592 KB |
Output is correct |
3 |
Correct |
20 ms |
4564 KB |
Output is correct |
4 |
Correct |
23 ms |
4640 KB |
Output is correct |
5 |
Correct |
20 ms |
4564 KB |
Output is correct |
6 |
Correct |
19 ms |
4620 KB |
Output is correct |
7 |
Correct |
19 ms |
4564 KB |
Output is correct |
8 |
Correct |
20 ms |
4584 KB |
Output is correct |
9 |
Correct |
33 ms |
4760 KB |
Output is correct |
10 |
Correct |
40 ms |
4684 KB |
Output is correct |
11 |
Correct |
29 ms |
4484 KB |
Output is correct |
12 |
Correct |
55 ms |
6520 KB |
Output is correct |
13 |
Correct |
81 ms |
8996 KB |
Output is correct |
14 |
Correct |
127 ms |
11172 KB |
Output is correct |
15 |
Correct |
147 ms |
11956 KB |
Output is correct |
16 |
Correct |
162 ms |
14144 KB |
Output is correct |
17 |
Correct |
212 ms |
17996 KB |
Output is correct |
18 |
Correct |
220 ms |
18488 KB |
Output is correct |
19 |
Correct |
245 ms |
20136 KB |
Output is correct |
20 |
Correct |
201 ms |
18056 KB |
Output is correct |