Submission #1111490

# Submission time Handle Problem Language Result Execution time Memory
1111490 2024-11-12T08:53:35 Z DuongKiet Teams (CEOI11_tea) C++17
0 / 100
2500 ms 262144 KB
#include <bits/stdc++.h>
#define N 1000005
#define inf 1e18
#define ll long long
#define ii pair <int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define SZ(x) (int) x.size()

const long long Mod = 1e9 + 7;

using namespace std;

int n;
struct cauthu{
    int c, id;
}a[N];
struct slteam{
    int c, id;
};
struct cmp{
    bool operator()(slteam &a, slteam &b){
        return a.c > b.c;
    }
};
void init(){

    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i].c;
        a[i].id = i;
    }
    sort(a + 1, a + 1 + n, [&](cauthu a, cauthu b){
            return a.c > b.c;
        });
    vector <vector<int> > team;
    vector <int> maketeam;
    int cur = -1;
    int pos = 1;
    bool kt = 1;
    while (kt) {
        maketeam.clear();
    for (int i = pos; i <= n; i++){
        if (cur == -1){
            cur = a[i].c - 1;
            maketeam.pb(a[i].id);
            continue;
        }
        if (cur > 0){
            cur--;
            maketeam.pb(a[i].id);
        }else{
            cur = a[i].c - 1;
            team.pb(maketeam);
            maketeam.clear();
            maketeam.pb(a[i].id);
        }
    }
    if (cur > 0){

        priority_queue<slteam, vector <slteam>, cmp> q;
        for (int i = 0; i < SZ(team); i++)
            q.push({SZ(team[i]), i});

        sort(all(maketeam), [&](int u, int v){return a[u].c < a[v].c;});

        while (a[maketeam.back()].c > SZ(maketeam) && !maketeam.empty()){
            slteam k = q.top();
            q.pop();
            team[k.id].pb(maketeam.back());
            q.push({SZ(team[k.id]), k.id});
            maketeam.pop_back();
            if (maketeam.empty()) break;
        }
        pos = maketeam.back();
    }
    else {kt = 0; if (!maketeam.empty()) team.pb(maketeam);}
    }
    cout << team.size() << '\n';
    for (vector <int> cur: team){
        cout << cur.size() << ' ';
        for (int x: cur)
            cout << x << " ";
        cout << '\n';
    }
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #define task "DIVTEAM"
    if (fopen(task".inp", "r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    init();
    return 0;
}

Compilation message

tea.cpp: In function 'int main()':
tea.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
tea.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Execution timed out 2593 ms 3948 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2562 ms 7408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2556 ms 10152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 592 KB Integer parameter [name=k_j] equals to 0, violates the range [1, 4999]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2569 ms 189432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 846 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 676 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 371 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 544 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1188 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -