#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define vi vector<int>
#define rep(i,x,n) for(int i=x; i<n; ++i)
#define For(i,n) rep(i,0,n)
#define pb push_back
#define f first
#define s second
#define endl "\n"
#define sp ' '
// #define sz size()
#define all(x) (x).begin(),(x).end()
const int N = 5e5+10, OO = 1e18, mod = 1e9+7;
void tr(int a, int b){cout << a << sp << b << endl;}
vi a[N], ans[N], cur[N];
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int n,d,m; cin >> n >> d >> m;
For(i,m){
int x; cin >> x;
a[x].pb(i+1);
}
int l=0, r = 1e7;
while(r > l+1){
int mid = (l+r)/2, ok = 1;
deque <pi> v;
rep(i,1,n+1) cur[i].clear();
rep(i,1,n+1){
int sz = v.size();
For(j, min(mid, sz)){
if(i-v.front().s > d) ok = 0;
cur[i].pb(v.front().f);
v.pop_front();
}
int c = a[i].size(), ava = mid - min(mid,sz);
for(int j=0; j < c; ++j){
if(j < ava) cur[i].pb(a[i][j]);
else v.pb({a[i][j],i});
}
}
if(ok){
r = mid;
rep(i,1,n+1) ans[i] = cur[i];
}
else l = mid;
}
cout << r << endl;
rep(i,1,n+1){
for(int j: ans[i]) cout << j << sp;
cout << 0 << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
31 ms |
41552 KB |
Memory limit exceeded |
2 |
Runtime error |
30 ms |
41612 KB |
Memory limit exceeded |
3 |
Runtime error |
29 ms |
41560 KB |
Memory limit exceeded |
4 |
Runtime error |
29 ms |
41552 KB |
Memory limit exceeded |
5 |
Runtime error |
30 ms |
41564 KB |
Memory limit exceeded |
6 |
Runtime error |
30 ms |
41552 KB |
Memory limit exceeded |
7 |
Runtime error |
32 ms |
41596 KB |
Memory limit exceeded |
8 |
Runtime error |
30 ms |
41592 KB |
Memory limit exceeded |
9 |
Runtime error |
50 ms |
40496 KB |
Memory limit exceeded |
10 |
Runtime error |
48 ms |
40476 KB |
Memory limit exceeded |
11 |
Runtime error |
28 ms |
39760 KB |
Memory limit exceeded |
12 |
Runtime error |
46 ms |
44112 KB |
Memory limit exceeded |
13 |
Runtime error |
66 ms |
50036 KB |
Memory limit exceeded |
14 |
Runtime error |
109 ms |
55308 KB |
Memory limit exceeded |
15 |
Runtime error |
96 ms |
58372 KB |
Memory limit exceeded |
16 |
Runtime error |
160 ms |
63300 KB |
Memory limit exceeded |
17 |
Runtime error |
211 ms |
65536 KB |
Execution killed with signal 9 |
18 |
Runtime error |
175 ms |
65536 KB |
Execution killed with signal 9 |
19 |
Runtime error |
174 ms |
65536 KB |
Execution killed with signal 9 |
20 |
Runtime error |
207 ms |
65536 KB |
Execution killed with signal 9 |