## Submission #403917

# Submission time Handle Problem Language Result Execution time Memory
403917 2021-05-13T15:04:07 Z SamAnd Carnival Tickets (IOI20_tickets) C++17
100 / 100
953 ms 73240 KB
```#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef long long ll;

long long find_maximum(int k, vector<vector<int> > x)
{
int n = x.size();
int m = x[0].size();
vector<vector<int> > ans;
for (int i = 0; i < n; i++)
{
vector<int> row(m);
for (int j = 0; j < m; j++)
{
row[j] = -1;
}
ans.push_back(row);
}

ll tans = 0;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < k; ++j)
{
tans -= x[i][j];
}
}

set<pair<int, int> > s;
vector<int> u;
for (int i = 0; i < n; ++i)
{
u.push_back(k - 1);
s.insert(m_p(x[i][k - 1] + x[i][m - 1], i));
}

for (int ii = 0; ii < n * k / 2; ++ii)
{
int i = (--s.end())->se;
s.erase(--s.end());

tans += (x[i][u[i]] + x[i][m - (k - u[i])]);
--u[i];
if (u[i] >= 0)
s.insert(m_p(x[i][u[i]] + x[i][m - (k - u[i])], i));
}

vector<int> l, r;
for (int i = 0; i < n; ++i)
{
l.push_back(u[i]);
r.push_back(m - (k - u[i]) + 1);
}

for (int ii = 0; ii < k; ++ii)
{
vector<int> v;
int q1 = 0;
int q2 = 0;
for (int i = 0; i < n; ++i)
{
if (l[i] == -1)
{
ans[i][r[i]++] = ii;
++q1;
}
else if (r[i] == m)
{
ans[i][l[i]--] = ii;
++q2;
}
else
{
v.push_back(i);
}
}
for (int i = 0; i < (n / 2) - q1; ++i)
{
ans[v[i]][r[v[i]]++] = ii;
}
for (int i = (n / 2) - q1; i < sz(v); ++i)
{
ans[v[i]][l[v[i]]--] = ii;
}
}

allocate_tickets(ans);
return tans;
}
```

#### Subtask #1 11.0 / 11.0

# 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 204 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 2 ms 716 KB Output is correct

#### Subtask #2 16.0 / 16.0

# 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 460 KB Output is correct
5 Correct 43 ms 3272 KB Output is correct
6 Correct 620 ms 73240 KB Output is correct

#### Subtask #3 14.0 / 14.0

# 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 460 KB Output is correct
5 Correct 38 ms 2464 KB Output is correct
6 Correct 607 ms 56800 KB Output is correct
7 Correct 646 ms 57216 KB Output is correct
8 Correct 6 ms 556 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 292 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 7 ms 828 KB Output is correct
13 Correct 28 ms 2172 KB Output is correct
14 Correct 21 ms 2136 KB Output is correct
15 Correct 640 ms 57780 KB Output is correct

#### Subtask #4 14.0 / 14.0

# 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 460 KB Output is correct
5 Correct 35 ms 3268 KB Output is correct
6 Correct 6 ms 780 KB Output is correct
7 Correct 8 ms 1100 KB Output is correct
8 Correct 934 ms 59440 KB Output is correct
9 Correct 859 ms 70980 KB Output is correct
10 Correct 870 ms 71104 KB Output is correct
11 Correct 887 ms 59228 KB Output is correct

#### Subtask #5 12.0 / 12.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 3 ms 460 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 4 ms 432 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 5 ms 520 KB Output is correct

#### Subtask #6 23.0 / 23.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 3 ms 460 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 4 ms 432 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 5 ms 520 KB Output is correct
13 Correct 28 ms 3180 KB Output is correct
14 Correct 40 ms 3252 KB Output is correct
15 Correct 32 ms 3152 KB Output is correct
16 Correct 35 ms 3312 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 36 ms 2576 KB Output is correct
21 Correct 43 ms 3108 KB Output is correct
22 Correct 31 ms 2628 KB Output is correct
23 Correct 34 ms 3192 KB Output is correct

#### Subtask #7 10.0 / 10.0

# 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 204 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 2 ms 716 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 3 ms 460 KB Output is correct
11 Correct 43 ms 3272 KB Output is correct
12 Correct 620 ms 73240 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 460 KB Output is correct
17 Correct 38 ms 2464 KB Output is correct
18 Correct 607 ms 56800 KB Output is correct
19 Correct 646 ms 57216 KB Output is correct
20 Correct 6 ms 556 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 292 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 7 ms 828 KB Output is correct
25 Correct 28 ms 2172 KB Output is correct
26 Correct 21 ms 2136 KB Output is correct
27 Correct 640 ms 57780 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 460 KB Output is correct
32 Correct 35 ms 3268 KB Output is correct
33 Correct 6 ms 780 KB Output is correct
34 Correct 8 ms 1100 KB Output is correct
35 Correct 934 ms 59440 KB Output is correct
36 Correct 859 ms 70980 KB Output is correct
37 Correct 870 ms 71104 KB Output is correct
38 Correct 887 ms 59228 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 3 ms 460 KB Output is correct
42 Correct 3 ms 460 KB Output is correct
43 Correct 3 ms 460 KB Output is correct
44 Correct 3 ms 460 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 3 ms 460 KB Output is correct
48 Correct 4 ms 432 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 5 ms 520 KB Output is correct
51 Correct 28 ms 3180 KB Output is correct
52 Correct 40 ms 3252 KB Output is correct
53 Correct 32 ms 3152 KB Output is correct
54 Correct 35 ms 3312 KB Output is correct
55 Correct 2 ms 332 KB Output is correct
56 Correct 3 ms 460 KB Output is correct
57 Correct 2 ms 332 KB Output is correct
58 Correct 36 ms 2576 KB Output is correct
59 Correct 43 ms 3108 KB Output is correct
60 Correct 31 ms 2628 KB Output is correct
61 Correct 34 ms 3192 KB Output is correct
62 Correct 70 ms 8428 KB Output is correct
63 Correct 71 ms 8428 KB Output is correct
64 Correct 100 ms 8712 KB Output is correct
65 Correct 381 ms 33292 KB Output is correct
66 Correct 399 ms 33688 KB Output is correct
67 Correct 9 ms 1100 KB Output is correct
68 Correct 6 ms 764 KB Output is correct
69 Correct 620 ms 73160 KB Output is correct
70 Correct 818 ms 72944 KB Output is correct
71 Correct 953 ms 64500 KB Output is correct
72 Correct 758 ms 52416 KB Output is correct
73 Correct 864 ms 52620 KB Output is correct
74 Correct 654 ms 59164 KB Output is correct
75 Correct 818 ms 51196 KB Output is correct