#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
#define inf 1000000000
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
priority_queue <pair<ll, pii> > pq;
bool used[1505][1505];
int cnt[1505], l[1505], r[1505];
vi v[1505];
pii a[1505];
long long find_maximum(int k, vector<vi> x) {
int n = x.size();
int m = x[0].size();
vector <vi> answer;
vi row(m, -1);
FOR(i, 0, n-1) {
answer.pb(row);
}
ll sum = 0;
FOR(i, 0, n-1) {
FOR(j, m-k, m-1) {
sum += x[i][j];
pq.push({-x[i][j] - x[i][j-m+k], {i, j-m+k}});
}
}
FOR(i, 0, n*k/2 - 1) {
auto tmp = pq.top();
pq.pop();
cnt[tmp.se.fi]++;
v[tmp.se.fi].pb(tmp.se.se);
answer[tmp.se.fi][tmp.se.se] = inf;
sum += tmp.fi;
}
FOR(i, 0, n-1) {
r[i] = k-1;
FORD(j, m-1, m-k) {
if (answer[i][j] == -1 && (int)v[i].size() < k) {
v[i].pb(j);
}
}
}
FOR(i, 0, k-1) {
FOR(j, 0, n-1) {
a[j] = {cnt[j], j};
}
sort(a, a+n);
reverse(a, a+n);
FOR(j, 0, n/2-1) {
answer[a[j].se][v[a[j].se][l[a[j].se]]] = i;
l[a[j].se]++;
cnt[a[j].se]--;
}
FOR(j, n/2, n-1) {
answer[a[j].se][v[a[j].se][r[a[j].se]]] = i;
r[a[j].se]--;
}
}
allocate_tickets(answer);
return sum;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
43 ms |
2432 KB |
Output is correct |
6 |
Correct |
777 ms |
51716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
360 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
33 ms |
3552 KB |
Output is correct |
6 |
Correct |
892 ms |
76128 KB |
Output is correct |
7 |
Correct |
964 ms |
82612 KB |
Output is correct |
8 |
Correct |
5 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
416 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
12 ms |
1276 KB |
Output is correct |
13 |
Correct |
30 ms |
3252 KB |
Output is correct |
14 |
Correct |
32 ms |
3440 KB |
Output is correct |
15 |
Correct |
1044 ms |
93832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
360 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
49 ms |
4588 KB |
Output is correct |
6 |
Correct |
11 ms |
1020 KB |
Output is correct |
7 |
Correct |
16 ms |
1276 KB |
Output is correct |
8 |
Correct |
1555 ms |
102296 KB |
Output is correct |
9 |
Correct |
1398 ms |
96312 KB |
Output is correct |
10 |
Correct |
1505 ms |
95652 KB |
Output is correct |
11 |
Correct |
1518 ms |
102352 KB |
Output is correct |
# |
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 |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
3 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 |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
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 |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
3 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 |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
3 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 |
31 ms |
2424 KB |
Output is correct |
14 |
Correct |
31 ms |
2560 KB |
Output is correct |
15 |
Correct |
39 ms |
3564 KB |
Output is correct |
16 |
Correct |
61 ms |
4580 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
640 KB |
Output is correct |
19 |
Correct |
3 ms |
512 KB |
Output is correct |
20 |
Correct |
36 ms |
3700 KB |
Output is correct |
21 |
Correct |
45 ms |
3688 KB |
Output is correct |
22 |
Correct |
49 ms |
4452 KB |
Output is correct |
23 |
Correct |
45 ms |
4324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 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 |
1 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 |
43 ms |
2432 KB |
Output is correct |
12 |
Correct |
777 ms |
51716 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
360 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
640 KB |
Output is correct |
17 |
Correct |
33 ms |
3552 KB |
Output is correct |
18 |
Correct |
892 ms |
76128 KB |
Output is correct |
19 |
Correct |
964 ms |
82612 KB |
Output is correct |
20 |
Correct |
5 ms |
896 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
416 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
12 ms |
1276 KB |
Output is correct |
25 |
Correct |
30 ms |
3252 KB |
Output is correct |
26 |
Correct |
32 ms |
3440 KB |
Output is correct |
27 |
Correct |
1044 ms |
93832 KB |
Output is correct |
28 |
Correct |
1 ms |
360 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
640 KB |
Output is correct |
32 |
Correct |
49 ms |
4588 KB |
Output is correct |
33 |
Correct |
11 ms |
1020 KB |
Output is correct |
34 |
Correct |
16 ms |
1276 KB |
Output is correct |
35 |
Correct |
1555 ms |
102296 KB |
Output is correct |
36 |
Correct |
1398 ms |
96312 KB |
Output is correct |
37 |
Correct |
1505 ms |
95652 KB |
Output is correct |
38 |
Correct |
1518 ms |
102352 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
3 ms |
512 KB |
Output is correct |
41 |
Correct |
3 ms |
512 KB |
Output is correct |
42 |
Correct |
3 ms |
512 KB |
Output is correct |
43 |
Correct |
4 ms |
640 KB |
Output is correct |
44 |
Correct |
3 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 |
5 ms |
640 KB |
Output is correct |
48 |
Correct |
3 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 |
31 ms |
2424 KB |
Output is correct |
52 |
Correct |
31 ms |
2560 KB |
Output is correct |
53 |
Correct |
39 ms |
3564 KB |
Output is correct |
54 |
Correct |
61 ms |
4580 KB |
Output is correct |
55 |
Correct |
1 ms |
384 KB |
Output is correct |
56 |
Correct |
3 ms |
640 KB |
Output is correct |
57 |
Correct |
3 ms |
512 KB |
Output is correct |
58 |
Correct |
36 ms |
3700 KB |
Output is correct |
59 |
Correct |
45 ms |
3688 KB |
Output is correct |
60 |
Correct |
49 ms |
4452 KB |
Output is correct |
61 |
Correct |
45 ms |
4324 KB |
Output is correct |
62 |
Correct |
102 ms |
6164 KB |
Output is correct |
63 |
Correct |
85 ms |
6264 KB |
Output is correct |
64 |
Correct |
129 ms |
11360 KB |
Output is correct |
65 |
Correct |
462 ms |
33752 KB |
Output is correct |
66 |
Correct |
602 ms |
44248 KB |
Output is correct |
67 |
Correct |
13 ms |
1276 KB |
Output is correct |
68 |
Correct |
7 ms |
1020 KB |
Output is correct |
69 |
Correct |
774 ms |
51900 KB |
Output is correct |
70 |
Correct |
1098 ms |
76724 KB |
Output is correct |
71 |
Correct |
1513 ms |
102392 KB |
Output is correct |
72 |
Correct |
1305 ms |
97840 KB |
Output is correct |
73 |
Correct |
1417 ms |
96520 KB |
Output is correct |
74 |
Correct |
1022 ms |
75976 KB |
Output is correct |
75 |
Correct |
1109 ms |
75384 KB |
Output is correct |