Submission #800948

#TimeUsernameProblemLanguageResultExecution timeMemory
800948becaidoCarnival Tickets (IOI20_tickets)C++17
100 / 100
548 ms54392 KiB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
#include "tickets.h"
using namespace std;

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 1505;

int cnt[SIZE];
bool is[SIZE];
int L[SIZE], R[SIZE];
priority_queue<pair<int, int>> pq;
ll find_maximum(int k, vector<vector<int>> x) {
    int n = x.size();
    int m = x[0].size();
    ll sum = 0;
    vector<vector<int>> ans;
    ans.resize(n, vector<int>(m, -1));
    fill(cnt, cnt + n, k);
    FOR (i, 0, n - 1) {
        sum += accumulate(x[i].begin() + m - cnt[i], x[i].end(), 0ll);
        pq.emplace(-x[i][0] - x[i][m - cnt[i]], i);
    }
    FOR (t, 1, n * k / 2) {
        auto [delta, i] = pq.top();
        pq.pop();
        sum += delta;
        cnt[i]--;
        if (cnt[i] > 0) pq.emplace(-x[i][k - cnt[i]] - x[i][m - cnt[i]], i);
    }
    pq = {};
    FOR (i, 0, n - 1) {
        pq.emplace(cnt[i], i);
        R[i] = m - 1;
    }
    FOR (t, 0, k - 1) {
        fill(is, is + n, 0);
        vector<pair<int, int>> vp;
        FOR (i, 0, n / 2 - 1) {
            auto [c, p] = pq.top();
            pq.pop();
            is[p] = 1;
            ans[p][R[p]--] = t;
            vp.pb(c - 1, p);
        }
        for (auto [c, i] : vp) pq.emplace(c, i);
        FOR (i, 0, n - 1) if (!is[i]) ans[i][L[i]++] = t;
    }
    allocate_tickets(ans);
    return sum;
}
#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...