Submission #1061651

# Submission time Handle Problem Language Result Execution time Memory
1061651 2024-08-16T11:26:53 Z vjudge1 Carnival Tickets (IOI20_tickets) C++17
100 / 100
717 ms 100180 KB
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;

using vi = vector<int>;
using ll = long long;
using ii = pair<int, int>;
using vll = vector<ll>;

ll find_maximum(int k, vector<vi> x) {
	int n = x.size();
	int m = x[0].size();
    vll Sum(n, 0), CntPlus(n, 0);
    auto calc = [&](int cul, int nr) { // cat as castiga
        return x[cul][m - 1 - nr] + x[cul][k - 1 - nr];
    };
    priority_queue<pair<ll, int> > PQ;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < k; ++j) {
            Sum[i] -= x[i][j];
        }
        PQ.push({calc(i, 0), i});
    }
    for(int nr = 0; nr < n * k / 2; ++nr) {
        auto [delta, cul] = PQ.top();
        PQ.pop();
        ++CntPlus[cul];
        Sum[cul] += delta;
        if(CntPlus[cul] < k) {
            PQ.push({calc(cul, CntPlus[cul]), cul});
        }
    }
    ll re = 0;
    for(auto it : Sum) re += it;

    vector<vector<ii>> Plus(n), Minus(n);

    vector<vi> S(n, vi(m, -1));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < k - CntPlus[i]; ++j)
            Minus[i].push_back({i, j});
        for(int j = 0; j < CntPlus[i]; ++j)
            Plus[i].push_back({i, m - 1 - j});
    }
    for(int nr = 0; nr < k; ++nr) {
        vi Neutre;
        vector<ii> Luate;
        int sum = 0;
        vi ord;
        for(int i = 0; i < n; ++i) {
            ord.push_back(i);
        }
        sort(ord.begin(), ord.end(), [&](auto a, auto b) {
            return abs((int)Plus[a].size() - (int)Minus[a].size()) 
            > abs((int)Plus[b].size() - (int)Minus[b].size());
        });
        for(int i = 0; i < n; ++i) {
            int it = ord[i], ramase = n - i;
            if((sum != ramase && Plus[it].size() > Minus[it].size()) || sum == -ramase) {
                Luate.push_back(Plus[it].back());
                Plus[it].pop_back();
                ++sum;
            } else {
                Luate.push_back(Minus[it].back());
                Minus[it].pop_back();
                --sum;
            }
        }
        vi Val;
        for(auto [c, p] : Luate) {
            S[c][p] = nr;
            Val.push_back(x[c][p]);
        }
    }
    allocate_tickets(S);
    return re;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 428 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 26 ms 3088 KB Output is correct
6 Correct 463 ms 62836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 14 ms 3160 KB Output is correct
6 Correct 412 ms 68944 KB Output is correct
7 Correct 445 ms 75372 KB Output is correct
8 Correct 4 ms 740 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 440 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 13 ms 2756 KB Output is correct
14 Correct 15 ms 3056 KB Output is correct
15 Correct 465 ms 76852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 26 ms 4556 KB Output is correct
6 Correct 4 ms 956 KB Output is correct
7 Correct 9 ms 1372 KB Output is correct
8 Correct 692 ms 100168 KB Output is correct
9 Correct 621 ms 94932 KB Output is correct
10 Correct 616 ms 93496 KB Output is correct
11 Correct 642 ms 100164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 3 ms 712 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 3 ms 712 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 23 ms 3192 KB Output is correct
14 Correct 21 ms 3420 KB Output is correct
15 Correct 17 ms 3784 KB Output is correct
16 Correct 22 ms 4456 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 20 ms 3260 KB Output is correct
21 Correct 21 ms 3896 KB Output is correct
22 Correct 19 ms 3676 KB Output is correct
23 Correct 22 ms 4320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 428 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 952 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 26 ms 3088 KB Output is correct
12 Correct 463 ms 62836 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 14 ms 3160 KB Output is correct
18 Correct 412 ms 68944 KB Output is correct
19 Correct 445 ms 75372 KB Output is correct
20 Correct 4 ms 740 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 440 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 5 ms 1116 KB Output is correct
25 Correct 13 ms 2756 KB Output is correct
26 Correct 15 ms 3056 KB Output is correct
27 Correct 465 ms 76852 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 2 ms 500 KB Output is correct
32 Correct 26 ms 4556 KB Output is correct
33 Correct 4 ms 956 KB Output is correct
34 Correct 9 ms 1372 KB Output is correct
35 Correct 692 ms 100168 KB Output is correct
36 Correct 621 ms 94932 KB Output is correct
37 Correct 616 ms 93496 KB Output is correct
38 Correct 642 ms 100164 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 3 ms 712 KB Output is correct
42 Correct 2 ms 448 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 2 ms 600 KB Output is correct
49 Correct 2 ms 604 KB Output is correct
50 Correct 2 ms 604 KB Output is correct
51 Correct 23 ms 3192 KB Output is correct
52 Correct 21 ms 3420 KB Output is correct
53 Correct 17 ms 3784 KB Output is correct
54 Correct 22 ms 4456 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 2 ms 600 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 20 ms 3260 KB Output is correct
59 Correct 21 ms 3896 KB Output is correct
60 Correct 19 ms 3676 KB Output is correct
61 Correct 22 ms 4320 KB Output is correct
62 Correct 46 ms 8536 KB Output is correct
63 Correct 64 ms 8532 KB Output is correct
64 Correct 66 ms 11284 KB Output is correct
65 Correct 227 ms 38424 KB Output is correct
66 Correct 323 ms 43368 KB Output is correct
67 Correct 7 ms 1372 KB Output is correct
68 Correct 4 ms 860 KB Output is correct
69 Correct 389 ms 73464 KB Output is correct
70 Correct 552 ms 86360 KB Output is correct
71 Correct 717 ms 100180 KB Output is correct
72 Correct 524 ms 84308 KB Output is correct
73 Correct 548 ms 96276 KB Output is correct
74 Correct 438 ms 71528 KB Output is correct
75 Correct 497 ms 84052 KB Output is correct