This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<int, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
const int MAX = 1000010;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
set<pair<int, int>> st;
for (int i = 0; i < n; i++) {
st.emplace(a[i], i);
}
vector<vector<int>> teams;
while (sz(st) > 0) {
auto it = prev(st.end());
int v = it->first;
if (v > sz(st)) break;
teams.push_back({});
while (v--) {
teams.back().push_back(prev(st.end())->second);
st.erase(prev(st.end()));
}
}
set<pair<int, int>> t;
for (int i = 0; i < sz(teams); i++) {
t.emplace(sz(teams[i]), i);
}
while (sz(st) > 0) {
auto it = t.begin();
int idx = it->second;
t.erase(it);
teams[idx].push_back(st.begin()->second);
st.erase(st.begin());
t.emplace(sz(teams[idx]), idx);
}
cout << sz(teams) << "\n";
for (int i = 0; i < sz(teams); i++) {
cout << sz(teams[i]) << " ";
for (int j = 0; j < sz(teams[i]); j++) {
cout << teams[i][j] + 1 << " ";
}
cout << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |