Submission #986793

# Submission time Handle Problem Language Result Execution time Memory
986793 2024-05-21T08:41:58 Z LOLOLO Teams (CEOI11_tea) C++17
0 / 100
106 ms 56268 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 1e6 + 10;
vector <int> pos[N];
int a[N], dp[N], pr[N], n;
pair <int, int> b[N];

vector < vector <int>> bin(int lim) {
    vector < vector <int>> A, B;
    B.clear();

    int lst = n;
    while (lst) {
        int nxt = -1;
        for (int j = lst - 1; j >= max(0, lst - lim); j--) {
            if (dp[j] + 1 == dp[lst] && lst - j + 1 >= b[lst].f) {
                nxt = j;
                break;
            }
        }

        if (nxt == -1)
            return B;

        vector <int> v;
        for (int j = nxt + 1; j <= lst; j++) {
            v.pb(b[j].s);
        }

        lst = nxt;

        A.pb(v);
    }

    return A;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pos[a[i]].pb(i);
    }

    int sz = 0;
    for (int i = 1; i <= n; i++) {
        for (auto x : pos[i]) {
            sz++;
            b[sz] = {i, x};
        } 
    }

    dp[0] = pr[0] = 0;

    for (int i = 1; i <= n; i++) {
        if (i < b[i].f) {
            dp[i] = -1;
        } else {
            dp[i] = pr[i - b[i].f] + 1;
        }

        pr[i] = dp[i] > dp[pr[i - 1]] ? i : pr[i - 1];
    }

    int l = 0, r = n, m, ans = n;
    while (l <= r) {
        m = (l + r) / 2;
        vector < vector <int>> save = bin(m);
        if (sz(save)) {
            ans = m;
            r = m - 1;
        } else {
            l = m + 1;
        }
    }

    cout << dp[n] << '\n';
    vector < vector <int>> save = bin(ans);

    for (auto x : save) {
        cout << sz(x) << " ";
        for (auto k : x)
            cout << k << " ";

        cout << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 24664 KB Output is correct
2 Incorrect 10 ms 23896 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 24668 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23896 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 24880 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 23900 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 26456 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 26712 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 46880 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 106 ms 54980 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 102 ms 56268 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -