Submission #691794

# Submission time Handle Problem Language Result Execution time Memory
691794 2023-01-31T15:02:20 Z Johann Teams (CEOI11_tea) C++14
100 / 100
647 ms 39796 KB
#include "bits/stdc++.h"
using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

vi konstruct(vpii &A, int limit)
{
    int n = sz(A);
    vi last(n + 1, -1);
    vi dp(n + 1, 0);
    vi lastMaxIdx(n + 1, 0);
    for (int i = 1; i <= n; ++i)
    {
        // interval to search: [ i - limit, i - A[i].first ] (inclusive borders)
        int teams, la;
        if (i >= A[i - 1].first)
        {
            int tmp = lastMaxIdx[i - A[i - 1].first];
            if (tmp < i - limit)
                teams = -1, la = -1;
            else
                teams = dp[tmp] + 1, la = tmp;
        }
        else
        {
            teams = -1, la = -1;
        }
        dp[i] = teams;
        last[i] = la;
        lastMaxIdx[i] = lastMaxIdx[i - 1];
        if (dp[i] >= dp[lastMaxIdx[i]])
            lastMaxIdx[i] = i;
    }
    vi ans;
    int idx = n;
    while (idx > 0)
    {
        ans.push_back(idx - 1);
        idx = last[idx];
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vpii A(n);
    for (int i = 0; i < n; ++i)
        cin >> A[i].first, A[i].second = i + 1;

    sort(all(A));

    int opt = sz(konstruct(A, n));
    int l = A.back().first, r = n;
    while (l < r)
    {
        int m = (l + r) / 2;
        int ans = sz(konstruct(A, m));
        if (ans < opt)
            l = m + 1;
        else
            r = m;
    }
    vi order = konstruct(A, l);
    reverse(all(order));
    cout << sz(order) << "\n";
    int idx = 0;
    for (int x : order)
    {
        cout << x - idx + 1 << " ";
        while (idx <= x)
            cout << A[idx++].second << " ";
        cout << "\n";
    }
    cout << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1952 KB Output is correct
2 Correct 31 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2100 KB Output is correct
2 Correct 32 ms 2512 KB Output is correct
3 Correct 34 ms 2592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 321 ms 15056 KB Output is correct
2 Correct 338 ms 22636 KB Output is correct
3 Correct 344 ms 19528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 446 ms 19964 KB Output is correct
2 Correct 647 ms 39796 KB Output is correct
3 Correct 441 ms 29948 KB Output is correct
4 Correct 412 ms 28356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 436 ms 20060 KB Output is correct
2 Correct 226 ms 27656 KB Output is correct
3 Correct 428 ms 30712 KB Output is correct
4 Correct 448 ms 25736 KB Output is correct