#include <bits/stdc++.h>
#define ii pair < int , int >
#define fi first
#define se second
#define int long long
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
void maximize(int &A, int B)
{
if(A < B) A = B;
return;
}
void minimize(int &A, int B)
{
if(A > B) A = B;
return;
}
const int N = 1e3 + 5;
const int mod = 1e9 + 7;
int n;
ii a[N];
vector < int > team[N];
priority_queue < ii , vector < ii > , greater < ii > > q;
bool cmp(ii a, ii b)
{
return a.fi > b.fi;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
FOR(i, 1, n){
cin >> a[i].fi;
a[i].se = i;
}
sort(a + 1, a + n + 1, cmp);
int cnt = 0, save = n + 1;
FOR(i, 1, n){
if(i + a[i].fi - 1 > n){
save = i;
break;
}
cnt++;
for(int j = i; j <= i + a[i].fi - 1; j++){
team[cnt].push_back(a[j].se);
}
i = i + a[i].fi - 1;
}
FOR(i, 1, cnt){
q.push(ii((int)team[i].size(), i));
}
FOR(i, save, n){
int I = q.top().se;
q.pop();
team[I].push_back(a[i].se);
q.push(ii((int)team[I].size(), I));
}
cout << cnt << '\n';
FOR(i, 1, cnt){
cout << (int)team[i].size() << " ";
for(int &v : team[i]){
cout << v << " ";
}
cout << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
764 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |