| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 648884 | messiuuuuu | Teams (CEOI11_tea) | C++14 | 457 ms | 32544 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>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e6 + 5;
const ll INF = 1e9 + 5;
int n, a[MAXN];
void Input()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
}
int cs[MAXN];
int dp[MAXN], last[MAXN], tsz[MAXN];
int Cal(int lim)
{
    dp[n] = 0;
    for (int i = 1; i <= n; i++)
    {
        int x = a[cs[i]];
        if (i < x || (dp[last[i - x]] + 1 < dp[last[i - 1]] && i < n))
        {
            last[i] = last[i - 1];
        } else
        {
            int sz = i - last[i - x];
            int newdp = dp[last[i - x]] + 1;
            if (sz <= lim && (i == n || newdp >= dp[last[i - 1]]))
            {
                last[i] = i;
                dp[i] = newdp;
                tsz[i] = sz;
            } else
            {
                last[i] = last[i - 1];
            }
        }
    }
    return dp[n];
}
void Solve()
{
    iota(cs + 1, cs + n + 1, 1);
    sort(cs + 1, cs + n + 1, [](int i, int j)
         {
             return a[i] < a[j];
         });
    int t = Cal(n);
    int l = 1, r = n;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        if (Cal(mid) == t)
        {
            r = mid - 1;
        } else
        {
            l = mid + 1;
        }
    }
    Cal(l);
    cout << dp[n] << '\n';
    int p = n;
    while (p > 0)
    {
        int sz = tsz[p];
        cout << sz << ' ';
        for (int i = 0; i < sz; i++, p--)
        {
            cout << cs[p] << ' ';
        }
        cout << '\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(task".INP","r"))
    {
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    Input();
    Solve();
}
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... | ||||
