# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
541616 | bigg | Teams (CEOI11_tea) | C++14 | 593 ms | 129728 KiB |
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;
const int MAXN = 1e6 + 10;
const int INF = 1e9 + 7;
int n;
int dp[MAXN], pp[MAXN];
pair<int, int> kids[MAXN];
vector<vector<int> > team;
set<pair<int, int> > tam;
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++){
scanf("%d", &kids[i].first);
kids[i].second = i;
}
sort(kids + 1, kids + 1 + n);
reverse(kids + 1, kids + 1 + n);
memset(dp, -INF, sizeof(dp));
dp[n + 1] = 0;
for(int i = n; i > 0; i--){
dp[i] = dp[i + 1];
if(i + kids[i].first <= n + 1) dp[i] = max(dp[i], dp[i + kids[i].first] + 1);
if(i == 1) dp[i] = dp[i + kids[i].first] + 1;
if(i + kids[i].first <= n + 1 && dp[i] == dp[i + kids[i].first] + 1) pp[i] = i + kids[i].first;
else pp[i] = i + 1;
}
for(int i = 1; i <= n; i++){
int curkid = kids[i].second;
int qnt = kids[i].first;
if(pp[i] != i + qnt){
int tamteam = tam.begin()->second;
tam.erase(tam.begin());
team[tamteam].push_back(curkid);
tam.insert(make_pair(team[tamteam].size(), tamteam));
continue;
}
team.push_back(vector<int> (1, curkid));
int idx = team.size() - 1;
while(--qnt) team[idx].push_back(kids[++i].second);
tam.insert(make_pair(team[idx].size(), idx));
}
printf("%lu\n", team.size());
for(int i = 0; i < team.size(); i++){
printf("%lu ", team[i].size());
sort(team[i].begin(), team[i].end());
for(int j = 0; j < team[i].size(); j++) printf("%d ", team[i][j]);
printf("\n");
}
}
Compilation message (stderr)
# | 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... |