## Submission #302697

# Submission time Handle Problem Language Result Execution time Memory
302697 2020-09-19T04:21:53 Z leejseo Carnival Tickets (IOI20_tickets) C++17
100 / 100
1434 ms 95408 KB
```#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int N, M, K;

vector<vector<int>> ans;

vector<pair<int, int>> A[1505], B[1505];
bool vis[1505];

int cmp(const vector<pair<int, int>> &x, const vector<pair<int, int>> &y){
return x.size() > y.size();
}

priority_queue<pair<int, int>> pq;

ll find_maximum(int k, vector<vector<int>> x) {
N = x.size(); M= x[0].size(); K = k;
for (int i = 0; i < N; i++) {
vector<int> row(M);
ans.push_back(row);
}
priority_queue<pair<int, pair<int, int>>> pq;
ll res = 0;
for (int i=0; i<N; i++) for (int j=0; j<M; j++) ans[i][j] = -1;
for (int k=0; k<K; k++){
for (int i=0; i<N; i++){
res -= x[i][k];
ans[i][k] = -2;
pq.push(make_pair(x[i][M-K+k]+x[i][k], make_pair(i, k)));
}
}
int cnt = 0;
while (cnt < N*K/2){
int a, b, c;
tie(b, c) = pq.top().second;
a = pq.top().first;
pq.pop();
++cnt;
res += 1LL * a;
ans[b][c] = -1;
ans[b][M-K+c] = -3;
}
vector<vector<pair<int, int>>> I(N), J(N);
for (int i=0; i<N; i++){
for (int j=0; j<M; j++){
if (ans[i][j] == -2) I[i].push_back(make_pair(i, j));
else if (ans[i][j] == -3) J[i].push_back(make_pair(i, j));
}
}
for (int k=0; k<K; k++){
sort(I.begin(), I.end(), cmp);
memset(vis, 0, sizeof(vis));
for (int i=0; i<N/2; i++){
int a, b;
tie(a, b) = I[i].back(); I[i].pop_back();
ans[a][b] = k;
vis[a] = 1;
}
for (int i=0; i<N; i++){
int a, b;
if (J[i].empty()) continue;
tie(a, b) = J[i].back();
if (vis[a]) continue;
J[i].pop_back();
ans[a][b] = k;
vis[a] = 1;
}
}
allocate_tickets(ans);
return res;
}
```

#### Subtask #1 11.0 / 11.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 2 ms 896 KB Output is correct

#### Subtask #2 16.0 / 16.0

# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 31 ms 2552 KB Output is correct
6 Correct 718 ms 51704 KB Output is correct

#### Subtask #3 14.0 / 14.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 31 ms 3316 KB Output is correct
6 Correct 886 ms 70192 KB Output is correct
7 Correct 1012 ms 80620 KB Output is correct
8 Correct 5 ms 832 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1220 KB Output is correct
13 Correct 29 ms 3192 KB Output is correct
14 Correct 31 ms 3312 KB Output is correct
15 Correct 1116 ms 84880 KB Output is correct

#### Subtask #4 14.0 / 14.0

# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 49 ms 4472 KB Output is correct
6 Correct 8 ms 968 KB Output is correct
7 Correct 10 ms 1344 KB Output is correct
8 Correct 1409 ms 95408 KB Output is correct
9 Correct 1336 ms 90624 KB Output is correct
10 Correct 1332 ms 89088 KB Output is correct
11 Correct 1434 ms 95356 KB Output is correct

#### Subtask #5 12.0 / 12.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 4 ms 640 KB Output is correct

#### Subtask #6 23.0 / 23.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 4 ms 640 KB Output is correct
13 Correct 30 ms 2464 KB Output is correct
14 Correct 31 ms 2468 KB Output is correct
15 Correct 39 ms 3316 KB Output is correct
16 Correct 48 ms 4464 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 3 ms 640 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 36 ms 3552 KB Output is correct
21 Correct 41 ms 3444 KB Output is correct
22 Correct 41 ms 4204 KB Output is correct
23 Correct 46 ms 4080 KB Output is correct

#### Subtask #7 10.0 / 10.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 2 ms 896 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 31 ms 2552 KB Output is correct
12 Correct 718 ms 51704 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 31 ms 3316 KB Output is correct
18 Correct 886 ms 70192 KB Output is correct
19 Correct 1012 ms 80620 KB Output is correct
20 Correct 5 ms 832 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 10 ms 1220 KB Output is correct
25 Correct 29 ms 3192 KB Output is correct
26 Correct 31 ms 3312 KB Output is correct
27 Correct 1116 ms 84880 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 4 ms 640 KB Output is correct
32 Correct 49 ms 4472 KB Output is correct
33 Correct 8 ms 968 KB Output is correct
34 Correct 10 ms 1344 KB Output is correct
35 Correct 1409 ms 95408 KB Output is correct
36 Correct 1336 ms 90624 KB Output is correct
37 Correct 1332 ms 89088 KB Output is correct
38 Correct 1434 ms 95356 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 4 ms 512 KB Output is correct
42 Correct 3 ms 640 KB Output is correct
43 Correct 3 ms 640 KB Output is correct
44 Correct 4 ms 640 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 3 ms 640 KB Output is correct
48 Correct 4 ms 640 KB Output is correct
49 Correct 3 ms 640 KB Output is correct
50 Correct 4 ms 640 KB Output is correct
51 Correct 30 ms 2464 KB Output is correct
52 Correct 31 ms 2468 KB Output is correct
53 Correct 39 ms 3316 KB Output is correct
54 Correct 48 ms 4464 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 3 ms 640 KB Output is correct
57 Correct 2 ms 512 KB Output is correct
58 Correct 36 ms 3552 KB Output is correct
59 Correct 41 ms 3444 KB Output is correct
60 Correct 41 ms 4204 KB Output is correct
61 Correct 46 ms 4080 KB Output is correct
62 Correct 86 ms 6136 KB Output is correct
63 Correct 83 ms 6264 KB Output is correct
64 Correct 133 ms 10988 KB Output is correct
65 Correct 454 ms 31196 KB Output is correct
66 Correct 589 ms 41552 KB Output is correct
67 Correct 10 ms 1344 KB Output is correct
68 Correct 8 ms 968 KB Output is correct
69 Correct 713 ms 51712 KB Output is correct
70 Correct 1066 ms 70008 KB Output is correct
71 Correct 1403 ms 95384 KB Output is correct
72 Correct 1225 ms 91644 KB Output is correct
73 Correct 1334 ms 90164 KB Output is correct
74 Correct 919 ms 69936 KB Output is correct
75 Correct 1067 ms 69044 KB Output is correct