답안 #310123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
310123 2020-10-05T21:39:04 Z fishy15 Teams (CEOI11_tea) C++14
100 / 100
394 ms 84716 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});
            }
        }
    }

    set<int> to_assign;
    vector<vector<int>> ans;
    int cur = n;

    while (cur > 0) {
        int nxt_cur = cur - dp[cur][2];
        if (nxt_cur == cur) {
            to_assign.insert(cur - 1);
            cur--;
        } else {
            ans.push_back({});
            for (int i = nxt_cur; i < cur; i++) {
                ans.back().push_back(players[i].second);
            }
            cur = nxt_cur;
        }
    }

    int idx = dp[n][0] - 1;
    for (int i : to_assign) {
        while ((int)(ans[idx].size()) == dp[n][1]) {
            idx--;
        }
        ans[idx].push_back(players[i].second);
    }

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

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


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3320 KB Output is correct
2 Correct 24 ms 3328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 3448 KB Output is correct
2 Correct 23 ms 2940 KB Output is correct
3 Correct 28 ms 3708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 23928 KB Output is correct
2 Correct 232 ms 25392 KB Output is correct
3 Correct 241 ms 24788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 323 ms 32240 KB Output is correct
2 Correct 394 ms 84716 KB Output is correct
3 Correct 317 ms 33712 KB Output is correct
4 Correct 295 ms 27636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 321 ms 31116 KB Output is correct
2 Correct 228 ms 30944 KB Output is correct
3 Correct 306 ms 31864 KB Output is correct
4 Correct 336 ms 36908 KB Output is correct