Submission #227717

#TimeUsernameProblemLanguageResultExecution timeMemory
227717dolphingarlicTeams (CEOI11_tea)C++14
80 / 100
549 ms81848 KiB
#include <bits/stdc++.h>
using namespace std;

pair<int, int> a[1000001];
vector<vector<int>> teams;
priority_queue<pair<int, int>> pq;

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i].first);
        a[i].second = i;
    }
    sort(a + 1, a + n + 1);

    while (n) {
        if (a[n].first > n) {
            int sz, idx;
            tie(sz, idx) = pq.top();
            pq.pop();
            teams[idx].push_back(a[n--].second);
            pq.push({sz - 1, idx});
        } else {
            int ptr = n;
            teams.push_back({});
            while (n - ptr != a[n].first) teams.back().push_back(a[ptr--].second);
            pq.push({-teams.back().size(), teams.size() - 1});
            n = ptr;
        }
    }

    printf("%d\n", teams.size());
    for (vector<int> i : teams) {
        printf("%d", i.size());
        for (int j : i) printf(" %d", j);
        printf("\n");
    }
    return 0;
}

Compilation message (stderr)

tea.cpp: In function 'int main()':
tea.cpp:33:32: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<int> >::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", teams.size());
                    ~~~~~~~~~~~~^
tea.cpp:35:30: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
         printf("%d", i.size());
                      ~~~~~~~~^
tea.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
tea.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i].first);
         ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...