# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
510088 | blue | Teams (CEOI11_tea) | C++17 | 328 ms | 54840 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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using vi = vector<int>;
using pii = pair<int, int>;
using vvi = vector<vi>;
#define sz(x) int(x.size())
const int INF = 100'000'000;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
pii a[1+n];
for(int i = 1; i <= n; i++)
{
cin >> a[i].first;
a[i].second = i;
}
sort(a+1, a+n+1);
int t;
vi dp(1+n);
vi occ[1+n];
vi bit(1+n+1, -INF);
// bit[0 +1] = 0;
for(int j = 0 +1; j <= n +1; j += j&-j) bit[j] = 0;
occ[0].push_back(0);
for(int i = 1; i <= n; i++)
{
t = -INF;
if(a[i].first > i)
{
;
}
else
{
for(int j = i - a[i].first +1; j >= 0 +1; j -= j&-j)
t = max(t, bit[j]+1);
// cerr << i << " -> " << i - a[i].first << '\n';
for(int j = i +1; j <= n +1; j += j&-j)
bit[j] = max(bit[j], t);
}
dp[i] = t;
if(t != -INF) occ[dp[i]].push_back(i);
// cerr << i << " : " << t << '\n';
}
vvi teams;
int I = n;
// cerr << "done\n";
while(t)
{
// cerr << "I = " << I << '\n';
teams.push_back(vi(0));
// cerr << "A\n";
while(sz(occ[t-1]) >= 2 && occ[t-1].back() > I - a[I].first)
occ[t-1].pop_back();
// cerr << "B\n";
// cerr << t-1 << " : " << sz(occ[t-1]) << '\n';
for(int j = occ[t-1].back()+1; j <= I; j++)
teams.back().push_back(a[j].second);
// cerr << "C\n";
I = occ[t-1].back();
// cerr << "D\n";
t--;
}
cout << sz(teams) << '\n';
for(int y = 0; y < sz(teams); y++)
{
cout << sz(teams[y]) << ' ';
for(int z: teams[y]) cout << z << ' ';
cout << '\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... |