#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 3e5 + 2;
const int K = 17;
const int M = 1 << K;
const ll linf = 1e18;
pair<int, int> mx[M][2], pom[M][2];
vector<int> pos[M];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
int k = n / 2;
vector<int> a(n), cnt(m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int x; cin >> x;
if (x == 1) {
cnt[j] += 1;
a[i] += 1 << j;
}
}
}
int www = 0;
int p = 0, q = 0;
for (int i = 0; i < m; i++) {
if (cnt[i] >= k + 2) www++;
if (cnt[i] == k + 1) p += (1 << i);
if (cnt[i] == k) q += (1 << i);
}
for (int i = 0; i < n; i++) a[i] ^= p ^ q;
if (n <= 3000) {
for (int i = 0; i < n; i++) {
int mx = 0;
for (int j = 0; j < n; j++) if (i != j) {
smax(mx, __builtin_popcount(p & (a[i] | a[j])) + __builtin_popcount(q & (a[i] & a[j])));
}
cout << mx + www << en;
}
return 0;
}
for (int i = 0; i < n; i++) {
if (pos[a[i]].size() < 2) pos[a[i]].push_back(i);
}
for (int mask = M - 1; mask >= 0; mask--) {
int o = __builtin_popcount(mask);
pom[mask][0] = pom[mask][1] = {-1, -1};
for (int i = 0; i < pos[mask].size(); i++) pom[mask][i] = {o, pos[mask][i]};
for (int i = 0; i < K; i++) {
int sm = (1 << i) ^ mask;
if (!((1 << i) & mask)) {
for (int j = 0; j < 2; j++) {
if (pom[sm][j].second != -1 && pom[sm][j].second != pom[mask][1].second) {
pom[mask][1] = pom[mask][0];
pom[mask][0] = {o, pom[sm][j].second};
}
else if (pom[sm][j].second != -1 && pom[sm][j].second != pom[mask][0].second) {
pom[mask][1] = {o, pom[sm][j].second};
}
}
}
}
}
for (int mask = 0; mask < M; mask++) {
mx[mask][0] = mx[mask][1] = {-1, -1};
for (int smask = mask; smask >= 0; smask = (smask - 1) & mask) {
for (int j = 0; j < 2; j++) {
if (mx[smask][j] > mx[mask][0] && mx[smask][j].second != mx[mask][1].second) {
mx[mask][1] = mx[mask][0];
mx[mask][0] = mx[smask][j];
}
else if (mx[smask][j] > mx[mask][1] && mx[smask][j].second != mx[mask][0].second) mx[mask][1] = mx[smask][j];
}
if (smask == 0) break;
}
}
for (int i = 0; i < n; i++) {
int x = a[i] & q;
int y = a[i] ^ p;
y &= p;
x |= y;
int sol = www;
sol += __builtin_popcount(a[i] & p);
if (mx[x][0].second == i && mx[x][1].second != -1) sol += mx[x][1].first;
else if (mx[x][0].second != -1) sol += mx[x][0].first;
cout << sol << en;
}
return 0;
}
Compilation message
council.cpp: In function 'int main()':
council.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i = 0; i < pos[mask].size(); i++) pom[mask][i] = {o, pos[mask][i]};
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3284 KB |
Output is correct |
2 |
Correct |
2 ms |
3284 KB |
Output is correct |
3 |
Correct |
3 ms |
3284 KB |
Output is correct |
4 |
Correct |
3 ms |
3284 KB |
Output is correct |
5 |
Correct |
2 ms |
3408 KB |
Output is correct |
6 |
Correct |
3 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
3 ms |
3284 KB |
Output is correct |
9 |
Correct |
3 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3304 KB |
Output is correct |
11 |
Correct |
2 ms |
3284 KB |
Output is correct |
12 |
Correct |
4 ms |
3416 KB |
Output is correct |
13 |
Correct |
2 ms |
3284 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3408 KB |
Output is correct |
16 |
Correct |
3 ms |
3404 KB |
Output is correct |
17 |
Correct |
3 ms |
3284 KB |
Output is correct |
18 |
Correct |
2 ms |
3284 KB |
Output is correct |
19 |
Correct |
2 ms |
3284 KB |
Output is correct |
20 |
Correct |
2 ms |
3284 KB |
Output is correct |
21 |
Correct |
4 ms |
3300 KB |
Output is correct |
22 |
Correct |
2 ms |
3284 KB |
Output is correct |
23 |
Correct |
2 ms |
3404 KB |
Output is correct |
24 |
Correct |
3 ms |
3284 KB |
Output is correct |
25 |
Correct |
2 ms |
3284 KB |
Output is correct |
26 |
Correct |
2 ms |
3284 KB |
Output is correct |
27 |
Correct |
2 ms |
3284 KB |
Output is correct |
28 |
Correct |
3 ms |
3284 KB |
Output is correct |
29 |
Correct |
2 ms |
3408 KB |
Output is correct |
30 |
Correct |
3 ms |
3408 KB |
Output is correct |
31 |
Correct |
3 ms |
3284 KB |
Output is correct |
32 |
Correct |
3 ms |
3284 KB |
Output is correct |
33 |
Correct |
4 ms |
3284 KB |
Output is correct |
34 |
Correct |
3 ms |
3288 KB |
Output is correct |
35 |
Correct |
2 ms |
3284 KB |
Output is correct |
36 |
Correct |
2 ms |
3284 KB |
Output is correct |
37 |
Correct |
2 ms |
3284 KB |
Output is correct |
38 |
Correct |
3 ms |
3404 KB |
Output is correct |
39 |
Correct |
4 ms |
3284 KB |
Output is correct |
40 |
Correct |
3 ms |
3412 KB |
Output is correct |
41 |
Correct |
2 ms |
3284 KB |
Output is correct |
42 |
Correct |
2 ms |
3284 KB |
Output is correct |
43 |
Correct |
3 ms |
3284 KB |
Output is correct |
44 |
Correct |
2 ms |
3296 KB |
Output is correct |
45 |
Correct |
3 ms |
3416 KB |
Output is correct |
46 |
Correct |
2 ms |
3420 KB |
Output is correct |
47 |
Correct |
2 ms |
3284 KB |
Output is correct |
48 |
Correct |
2 ms |
3284 KB |
Output is correct |
49 |
Correct |
2 ms |
3284 KB |
Output is correct |
50 |
Correct |
2 ms |
3296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3284 KB |
Output is correct |
2 |
Correct |
2 ms |
3284 KB |
Output is correct |
3 |
Correct |
3 ms |
3284 KB |
Output is correct |
4 |
Correct |
3 ms |
3284 KB |
Output is correct |
5 |
Correct |
2 ms |
3408 KB |
Output is correct |
6 |
Correct |
3 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
3 ms |
3284 KB |
Output is correct |
9 |
Correct |
3 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3304 KB |
Output is correct |
11 |
Correct |
2 ms |
3284 KB |
Output is correct |
12 |
Correct |
4 ms |
3416 KB |
Output is correct |
13 |
Correct |
2 ms |
3284 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3408 KB |
Output is correct |
16 |
Correct |
3 ms |
3404 KB |
Output is correct |
17 |
Correct |
3 ms |
3284 KB |
Output is correct |
18 |
Correct |
2 ms |
3284 KB |
Output is correct |
19 |
Correct |
2 ms |
3284 KB |
Output is correct |
20 |
Correct |
2 ms |
3284 KB |
Output is correct |
21 |
Correct |
4 ms |
3300 KB |
Output is correct |
22 |
Correct |
2 ms |
3284 KB |
Output is correct |
23 |
Correct |
2 ms |
3404 KB |
Output is correct |
24 |
Correct |
3 ms |
3284 KB |
Output is correct |
25 |
Correct |
2 ms |
3284 KB |
Output is correct |
26 |
Correct |
2 ms |
3284 KB |
Output is correct |
27 |
Correct |
2 ms |
3284 KB |
Output is correct |
28 |
Correct |
3 ms |
3284 KB |
Output is correct |
29 |
Correct |
2 ms |
3408 KB |
Output is correct |
30 |
Correct |
3 ms |
3408 KB |
Output is correct |
31 |
Correct |
3 ms |
3284 KB |
Output is correct |
32 |
Correct |
3 ms |
3284 KB |
Output is correct |
33 |
Correct |
4 ms |
3284 KB |
Output is correct |
34 |
Correct |
3 ms |
3288 KB |
Output is correct |
35 |
Correct |
2 ms |
3284 KB |
Output is correct |
36 |
Correct |
2 ms |
3284 KB |
Output is correct |
37 |
Correct |
2 ms |
3284 KB |
Output is correct |
38 |
Correct |
3 ms |
3404 KB |
Output is correct |
39 |
Correct |
4 ms |
3284 KB |
Output is correct |
40 |
Correct |
3 ms |
3412 KB |
Output is correct |
41 |
Correct |
2 ms |
3284 KB |
Output is correct |
42 |
Correct |
2 ms |
3284 KB |
Output is correct |
43 |
Correct |
3 ms |
3284 KB |
Output is correct |
44 |
Correct |
2 ms |
3296 KB |
Output is correct |
45 |
Correct |
3 ms |
3416 KB |
Output is correct |
46 |
Correct |
2 ms |
3420 KB |
Output is correct |
47 |
Correct |
2 ms |
3284 KB |
Output is correct |
48 |
Correct |
2 ms |
3284 KB |
Output is correct |
49 |
Correct |
2 ms |
3284 KB |
Output is correct |
50 |
Correct |
2 ms |
3296 KB |
Output is correct |
51 |
Correct |
62 ms |
3460 KB |
Output is correct |
52 |
Correct |
60 ms |
3544 KB |
Output is correct |
53 |
Correct |
64 ms |
3468 KB |
Output is correct |
54 |
Correct |
57 ms |
3480 KB |
Output is correct |
55 |
Correct |
53 ms |
3424 KB |
Output is correct |
56 |
Correct |
59 ms |
3476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3284 KB |
Output is correct |
2 |
Correct |
645 ms |
9776 KB |
Output is correct |
3 |
Correct |
674 ms |
9780 KB |
Output is correct |
4 |
Correct |
619 ms |
9552 KB |
Output is correct |
5 |
Correct |
645 ms |
9864 KB |
Output is correct |
6 |
Incorrect |
680 ms |
9500 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3284 KB |
Output is correct |
2 |
Correct |
645 ms |
9776 KB |
Output is correct |
3 |
Correct |
674 ms |
9780 KB |
Output is correct |
4 |
Correct |
619 ms |
9552 KB |
Output is correct |
5 |
Correct |
645 ms |
9864 KB |
Output is correct |
6 |
Incorrect |
680 ms |
9500 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3284 KB |
Output is correct |
2 |
Correct |
645 ms |
9776 KB |
Output is correct |
3 |
Correct |
674 ms |
9780 KB |
Output is correct |
4 |
Correct |
619 ms |
9552 KB |
Output is correct |
5 |
Correct |
645 ms |
9864 KB |
Output is correct |
6 |
Incorrect |
680 ms |
9500 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3284 KB |
Output is correct |
2 |
Correct |
645 ms |
9776 KB |
Output is correct |
3 |
Correct |
674 ms |
9780 KB |
Output is correct |
4 |
Correct |
619 ms |
9552 KB |
Output is correct |
5 |
Correct |
645 ms |
9864 KB |
Output is correct |
6 |
Incorrect |
680 ms |
9500 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3284 KB |
Output is correct |
2 |
Correct |
2 ms |
3284 KB |
Output is correct |
3 |
Correct |
3 ms |
3284 KB |
Output is correct |
4 |
Correct |
3 ms |
3284 KB |
Output is correct |
5 |
Correct |
2 ms |
3408 KB |
Output is correct |
6 |
Correct |
3 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
3 ms |
3284 KB |
Output is correct |
9 |
Correct |
3 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3304 KB |
Output is correct |
11 |
Correct |
2 ms |
3284 KB |
Output is correct |
12 |
Correct |
4 ms |
3416 KB |
Output is correct |
13 |
Correct |
2 ms |
3284 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3408 KB |
Output is correct |
16 |
Correct |
3 ms |
3404 KB |
Output is correct |
17 |
Correct |
3 ms |
3284 KB |
Output is correct |
18 |
Correct |
2 ms |
3284 KB |
Output is correct |
19 |
Correct |
2 ms |
3284 KB |
Output is correct |
20 |
Correct |
2 ms |
3284 KB |
Output is correct |
21 |
Correct |
4 ms |
3300 KB |
Output is correct |
22 |
Correct |
2 ms |
3284 KB |
Output is correct |
23 |
Correct |
2 ms |
3404 KB |
Output is correct |
24 |
Correct |
3 ms |
3284 KB |
Output is correct |
25 |
Correct |
2 ms |
3284 KB |
Output is correct |
26 |
Correct |
2 ms |
3284 KB |
Output is correct |
27 |
Correct |
2 ms |
3284 KB |
Output is correct |
28 |
Correct |
3 ms |
3284 KB |
Output is correct |
29 |
Correct |
2 ms |
3408 KB |
Output is correct |
30 |
Correct |
3 ms |
3408 KB |
Output is correct |
31 |
Correct |
3 ms |
3284 KB |
Output is correct |
32 |
Correct |
3 ms |
3284 KB |
Output is correct |
33 |
Correct |
4 ms |
3284 KB |
Output is correct |
34 |
Correct |
3 ms |
3288 KB |
Output is correct |
35 |
Correct |
2 ms |
3284 KB |
Output is correct |
36 |
Correct |
2 ms |
3284 KB |
Output is correct |
37 |
Correct |
2 ms |
3284 KB |
Output is correct |
38 |
Correct |
3 ms |
3404 KB |
Output is correct |
39 |
Correct |
4 ms |
3284 KB |
Output is correct |
40 |
Correct |
3 ms |
3412 KB |
Output is correct |
41 |
Correct |
2 ms |
3284 KB |
Output is correct |
42 |
Correct |
2 ms |
3284 KB |
Output is correct |
43 |
Correct |
3 ms |
3284 KB |
Output is correct |
44 |
Correct |
2 ms |
3296 KB |
Output is correct |
45 |
Correct |
3 ms |
3416 KB |
Output is correct |
46 |
Correct |
2 ms |
3420 KB |
Output is correct |
47 |
Correct |
2 ms |
3284 KB |
Output is correct |
48 |
Correct |
2 ms |
3284 KB |
Output is correct |
49 |
Correct |
2 ms |
3284 KB |
Output is correct |
50 |
Correct |
2 ms |
3296 KB |
Output is correct |
51 |
Correct |
62 ms |
3460 KB |
Output is correct |
52 |
Correct |
60 ms |
3544 KB |
Output is correct |
53 |
Correct |
64 ms |
3468 KB |
Output is correct |
54 |
Correct |
57 ms |
3480 KB |
Output is correct |
55 |
Correct |
53 ms |
3424 KB |
Output is correct |
56 |
Correct |
59 ms |
3476 KB |
Output is correct |
57 |
Correct |
2 ms |
3284 KB |
Output is correct |
58 |
Correct |
645 ms |
9776 KB |
Output is correct |
59 |
Correct |
674 ms |
9780 KB |
Output is correct |
60 |
Correct |
619 ms |
9552 KB |
Output is correct |
61 |
Correct |
645 ms |
9864 KB |
Output is correct |
62 |
Incorrect |
680 ms |
9500 KB |
Output isn't correct |
63 |
Halted |
0 ms |
0 KB |
- |