#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000000 + 10;
pair<int,int> v[MAXN];
vector<int> t[MAXN];
vector<pair<int,int>> teams;
int marc[MAXN], ans = 0, n;
int addToTeam(int i, int have, int team){
int cur = i;
while(cur <= n){
if(v[cur].first > have){
int diff = v[cur].first - have;
// printf("difference of %d from %d to desired %d\n",cur,have,v[cur].first);
have = v[cur].first;
cur += diff;
}else{
// printf("forming a team from %d to %d with %d members\n",i,cur,have);
ans++;
for(int j = i;j<=cur;j++){
t[team].push_back(v[j].second);
}
teams.push_back(make_pair(have, team));
return cur;
}
}
return -1;
}
int main(){
cin >> n;
for(int i = 1;i<=n;i++){
int val; cin >> val;
v[i] = make_pair(val, i);
}
sort(v + 1, v + n + 1);
for(int i = 1;i<=n;i++){
// printf("(%d,%d)\n",v[i].first,v[i].second);
}
int lastId = n + 1; bool canForm = true;
for(int i = 1;i<=n;i++){
int tmp = addToTeam(i, 1, i);
if(tmp == -1){
canForm = false;
lastId = i;
break;
}else{
i = tmp;
}
}
for(int i = lastId; i<=n;i++){
marc[v[i].first] = i;
}
for(int i = lastId; i<=n;i++){
// printf("processing %d\n",i);
sort(teams.begin(), teams.end());
for(int j = 0;j<teams.size();j++){
// printf("-trying team %d\n",teams[j].second);
int diff = v[i].first - teams[j].first;
// printf("--there is %d %d's left and diff = %d\n", marc[v[i].first] - i + 1, v[i].first, diff);
if(marc[v[i].first] - i + 1 >= diff){
for(int k = 0;k<=diff && i <= n;k++){
// printf("inserting %d to team %d\n",i,teams[j].second);
t[teams[j].second].push_back(v[i].second);
teams[j].first++;
i++;
}
break;
}
}
}
cout << ans << "\n";
for(int i = 1;i<=n;i++){
int size = t[i].size();
if(size != 0){
cout << size << " ";
for(int j = 0;j<size;j++){
cout << t[i][j] << " ";
}
cout << "\n";
}
}
return 0;
}
Compilation message
tea.cpp: In function 'int main()':
tea.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int j = 0;j<teams.size();j++){
| ~^~~~~~~~~~~~~
tea.cpp:41:28: warning: variable 'canForm' set but not used [-Wunused-but-set-variable]
41 | int lastId = n + 1; bool canForm = true;
| ^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
Output is correct |
2 |
Correct |
15 ms |
23756 KB |
Output is correct |
3 |
Incorrect |
15 ms |
23732 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
23756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
23756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
23880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
23904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
51 ms |
25176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
25372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
343 ms |
38084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
507 ms |
42184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
487 ms |
41552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |