Submission #310120

# Submission time Handle Problem Language Result Execution time Memory
310120 2020-10-05T20:44:50 Z fishy15 Teams (CEOI11_tea) C++14
0 / 100
323 ms 31204 KB
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>

#define ll long long
#define ld long double
#define eps 1e-8
#define MOD 1000000007

#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f

// change if necessary
#define MAXN 1000010

using namespace std;

int n;
pair<int, int> players[MAXN];
// {num_teams, max_size, cur_size}
array<int, 3> dp[MAXN];

void cmp(array<int, 3> &a, const array<int, 3> &b) {
    if (a[0] == b[0]) {
        a = min(a, b);
    } else {
        a = max(a, b);
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> players[i].first;
        players[i].second = i;
    }

    sort(players, players + n, greater<pair<int, int>>());

    for (int i = 0; i <= n; i++) {
        dp[i] = {-1, 0};
    }

    dp[players[0].first] = {1, players[0].first, players[0].first};
    for (int i = 0; i < n; i++) {
        if (dp[i][0] != -1) {
            if (i == dp[i][0] * dp[i][1]) {
                cmp(dp[i + 1], {dp[i][0], dp[i][1] + 1, 0});
            } else {
                cmp(dp[i + 1], {dp[i][0], dp[i][1], 0});
            }
            if (i + players[i].first <= n) {
                cmp(dp[i + players[i].first], {dp[i][0] + 1, max(dp[i][1], players[i].first), players[i].first});
            }
        }
    }

    vector<vector<int>> ans = {{}};

    // absorb the last one
    if (dp[n][2] == 0) {
        dp[n][2] = 1;
        int cur = n - 1;
        while (dp[cur][2] == 0) cur--;
        dp[cur][2] = 0;
    }

/*     for (int i = 0; i <= n; i++) { */
/*         cout << dp[i][0] << ' ' << dp[i][1] << ' ' << dp[i][2] << '\n'; */
/*     } */

    for (int i = 1; i <= n; i++) {
        ans.back().push_back(players[i - 1].second); 
        if (dp[i][2]) {
            ans.push_back({});
        }
    }

    cout << dp[n][0] << '\n';

    for (auto &v : ans) {
        if (!v.empty()) {
            cout << v.size() << ' ';
            for (int i : v) cout << i + 1 << ' ';
            cout << '\n';
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 0 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Incorrect 2 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 3072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 237 ms 23676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 323 ms 30968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 321 ms 31204 KB Output isn't correct
2 Halted 0 ms 0 KB -