Submission #471465

# Submission time Handle Problem Language Result Execution time Memory
471465 2021-09-09T12:30:12 Z ljuba Carnival Tickets (IOI20_tickets) C++17
100 / 100
1226 ms 121020 KB
#include "tickets.h"
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

ll find_maximum(int k, vector<vector<int>> x) {
    int n = (int)x.size();
    int m = (int)x[0].size();
    ll ans = 0;
    vector<vector<int>> znak(n, vector<int>(m, 0));

    priority_queue<pair<ll, pair<int, int>>> pq;

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < k; ++j) {
            ans -= x[i][j];
            znak[i][j] = -1;
            int ind = k-1-j;
            ind = m-1-ind;
            ll dodaj = x[i][j] + x[i][ind];
            pq.push({dodaj, {i, j}});
        }
    }

    for(int uradi = 0; uradi < n*k/2; ++uradi) {
        auto tren = pq.top();
        ans += tren.first;
        pair<int, int> mesto = tren.second;
        pq.pop();

        znak[mesto.first][mesto.second] = 0;
        int ind = k-1-mesto.second;
        ind = m-1-ind;
        znak[mesto.first][ind] = 1;
    }

    vector<stack<int>> minus(n), plus(n);

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            if(znak[i][j] == -1) {
                minus[i].push(j);
            } else if(znak[i][j] == 1) {
                plus[i].push(j);
            }
        }
    }

    //for(int i = 0; i < n; ++i) {
        //for(int j = 0; j < m; ++j) {
            //cerr << znak[i][j] << " ";
        //}
        //cerr << endl;
    //}

    vector<vector<int>> odg(n, vector<int>(m, -1));

    for(int uradi = 0; uradi < k; ++uradi) {
        vector<bool> marked(n, false);
        vector<bool> plusici, minusici;
        plusici = marked;
        minusici = marked;
        for(int i = 0; i < n; ++i) {
            if(!minus[i].empty()) {
                minusici[i] = true;
            }
            if(!plus[i].empty()) {
                plusici[i] = true;
            }
        }

        vector<int> moraPlus, moraMinus;

        for(int i = 0; i < n; ++i) {
            if(plusici[i] && !minusici[i]) {
                moraPlus.push_back(i);
            }
            if(minusici[i] && !plusici[i]) {
                if((int)moraMinus.size() < n/2) {
                    marked[i] = true;
                }
                moraMinus.push_back(i);
            }
        }

        for(int i = 0; i < n && (int)moraMinus.size() < n/2; ++i) {
            if(marked[i])
                continue;
            if(!minus[i].empty()) {
                marked[i] = true;
                moraMinus.push_back(i);
            }
        }

        for(int i = 0; i < n; ++i) {
            if(marked[i]) {
                odg[i][minus[i].top()] = uradi;
                minus[i].pop();
            } else {
                odg[i][plus[i].top()] = uradi;
                plus[i].pop();
            }
        }
    }

    allocate_tickets(odg);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 800 KB Output is correct
6 Correct 3 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 4 ms 588 KB Output is correct
5 Correct 33 ms 3908 KB Output is correct
6 Correct 647 ms 64184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 31 ms 3776 KB Output is correct
6 Correct 742 ms 81532 KB Output is correct
7 Correct 832 ms 88644 KB Output is correct
8 Correct 5 ms 848 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 8 ms 1224 KB Output is correct
13 Correct 27 ms 3704 KB Output is correct
14 Correct 30 ms 3288 KB Output is correct
15 Correct 856 ms 94960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 40 ms 5056 KB Output is correct
6 Correct 7 ms 1096 KB Output is correct
7 Correct 9 ms 3272 KB Output is correct
8 Correct 1226 ms 121020 KB Output is correct
9 Correct 1111 ms 112184 KB Output is correct
10 Correct 1092 ms 111960 KB Output is correct
11 Correct 1171 ms 119980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 3 ms 620 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 588 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 3 ms 620 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 588 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 27 ms 4068 KB Output is correct
14 Correct 27 ms 4056 KB Output is correct
15 Correct 33 ms 4408 KB Output is correct
16 Correct 41 ms 5064 KB Output is correct
17 Correct 2 ms 300 KB Output is correct
18 Correct 3 ms 972 KB Output is correct
19 Correct 2 ms 844 KB Output is correct
20 Correct 32 ms 4040 KB Output is correct
21 Correct 37 ms 4448 KB Output is correct
22 Correct 35 ms 4408 KB Output is correct
23 Correct 37 ms 4896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 800 KB Output is correct
6 Correct 3 ms 2764 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 4 ms 588 KB Output is correct
11 Correct 33 ms 3908 KB Output is correct
12 Correct 647 ms 64184 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 292 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 3 ms 588 KB Output is correct
17 Correct 31 ms 3776 KB Output is correct
18 Correct 742 ms 81532 KB Output is correct
19 Correct 832 ms 88644 KB Output is correct
20 Correct 5 ms 848 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 8 ms 1224 KB Output is correct
25 Correct 27 ms 3704 KB Output is correct
26 Correct 30 ms 3288 KB Output is correct
27 Correct 856 ms 94960 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 3 ms 716 KB Output is correct
32 Correct 40 ms 5056 KB Output is correct
33 Correct 7 ms 1096 KB Output is correct
34 Correct 9 ms 3272 KB Output is correct
35 Correct 1226 ms 121020 KB Output is correct
36 Correct 1111 ms 112184 KB Output is correct
37 Correct 1092 ms 111960 KB Output is correct
38 Correct 1171 ms 119980 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 3 ms 588 KB Output is correct
41 Correct 2 ms 588 KB Output is correct
42 Correct 3 ms 588 KB Output is correct
43 Correct 3 ms 588 KB Output is correct
44 Correct 3 ms 620 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 3 ms 588 KB Output is correct
48 Correct 3 ms 716 KB Output is correct
49 Correct 3 ms 588 KB Output is correct
50 Correct 3 ms 716 KB Output is correct
51 Correct 27 ms 4068 KB Output is correct
52 Correct 27 ms 4056 KB Output is correct
53 Correct 33 ms 4408 KB Output is correct
54 Correct 41 ms 5064 KB Output is correct
55 Correct 2 ms 300 KB Output is correct
56 Correct 3 ms 972 KB Output is correct
57 Correct 2 ms 844 KB Output is correct
58 Correct 32 ms 4040 KB Output is correct
59 Correct 37 ms 4448 KB Output is correct
60 Correct 35 ms 4408 KB Output is correct
61 Correct 37 ms 4896 KB Output is correct
62 Correct 75 ms 9992 KB Output is correct
63 Correct 71 ms 10104 KB Output is correct
64 Correct 113 ms 13208 KB Output is correct
65 Correct 378 ms 42752 KB Output is correct
66 Correct 492 ms 50580 KB Output is correct
67 Correct 9 ms 3272 KB Output is correct
68 Correct 7 ms 1096 KB Output is correct
69 Correct 636 ms 83980 KB Output is correct
70 Correct 900 ms 94888 KB Output is correct
71 Correct 1212 ms 121004 KB Output is correct
72 Correct 1041 ms 101408 KB Output is correct
73 Correct 1081 ms 113136 KB Output is correct
74 Correct 816 ms 81500 KB Output is correct
75 Correct 862 ms 93912 KB Output is correct