#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define inf 1000000010
vector<int> indexes[1000001];
int main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vector<ii> A;
F0R(i, n) {
int x; cin >> x;
indexes[x].pb(i+1);
}
for (int i = 0; i <= n; i++) {
for (int j : indexes[i]) A.pb(mp(i, j));
}
int teams = 1;
vector<int> breakpoints;
for (int i = 0; i < n-A.back().f; i++) {
int curSz = 1;
while (curSz < A[i].f && i+1 < n-A.back().f) {
curSz++;
i++;
}
if (curSz >= A[i].f) {
teams++;
breakpoints.pb(i);
}
}
breakpoints.pb(n-1);
for (int i = breakpoints.size()-2; ~i; i--) {
int j;
for (j = breakpoints[i+1]-A[breakpoints[i+1]].f; ; j--) {
if (j-(i==0?-1:breakpoints[i-1]) >= A[j].f) break;
}
breakpoints[i] = j;
}
for (int i = 0; i < (int)breakpoints.size()-1; i++) {
int curSize = breakpoints[i]-(i==0?-1:breakpoints[i-1]);
int j;
for (j = i+1; j < (int)breakpoints.size(); j++) {
int nxtSize = breakpoints[j]-breakpoints[j-1];
if (nxtSize < (curSize+nxtSize)/(j-i+1)) {
curSize += nxtSize;
} else {
break;
}
}
for (int k = i; k < j; k++) {
breakpoints[k] = (k==0?-1:breakpoints[k-1]) + curSize/(j-i);
if (curSize % (j-i) >= j-k) {
breakpoints[k]++;
}
}
i = j-1;
}
cout << teams << endl;
int curIdx = 0;
for (int x : breakpoints) {
cout << x - curIdx + 1;
assert(x-curIdx+1>=A[x].f);
for (; curIdx <= x; curIdx++) cout << " " << A[curIdx].s;
cout << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
17 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
Output is correct |
2 |
Correct |
17 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
Output is correct |
2 |
Correct |
20 ms |
23788 KB |
Output is correct |
3 |
Correct |
18 ms |
23788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
24044 KB |
Output is correct |
2 |
Correct |
18 ms |
24044 KB |
Output is correct |
3 |
Correct |
20 ms |
24044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
24044 KB |
Output is correct |
2 |
Correct |
18 ms |
24044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
25700 KB |
Output is correct |
2 |
Correct |
34 ms |
25824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
25960 KB |
Output is correct |
2 |
Correct |
46 ms |
25760 KB |
Output is correct |
3 |
Correct |
36 ms |
25956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
40776 KB |
Output is correct |
2 |
Correct |
198 ms |
38960 KB |
Output is correct |
3 |
Correct |
174 ms |
39496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
224 ms |
45640 KB |
Output is correct |
2 |
Correct |
2440 ms |
52612 KB |
Output is correct |
3 |
Correct |
233 ms |
43600 KB |
Output is correct |
4 |
Correct |
261 ms |
43336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
234 ms |
44684 KB |
Output is correct |
2 |
Correct |
230 ms |
42760 KB |
Output is correct |
3 |
Correct |
215 ms |
45128 KB |
Output is correct |
4 |
Correct |
397 ms |
47028 KB |
Output is correct |