Submission #741686

# Submission time Handle Problem Language Result Execution time Memory
741686 2023-05-14T14:37:56 Z stevancv Council (JOI23_council) C++14
22 / 100
316 ms 59556 KB
#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 = 20;
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][0].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++) {
        int o = __builtin_popcount(mask);
        mx[mask][0] = pom[mask][0];
        mx[mask][1] = pom[mask][1];
        for (int i = 0; i < m; i++) {
            if (!((1 << i) & mask)) continue;
            for (int j = 0; j < 2; j++) {
                if (mx[i][j] > mx[mask][0] && mx[i][j].second != mx[mask][0].second) {
                    mx[mask][1] = mx[mask][0];
                    mx[mask][0] = mx[i][j];
                }
                else if (mx[i][j] > mx[mask][1] && mx[i][j].second != mx[mask][0].second) mx[mask][1] = mx[i][j];
            }
        }
    }
    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]};
      |                         ~~^~~~~~~~~~~~~~~~~~
council.cpp:73:13: warning: unused variable 'o' [-Wunused-variable]
   73 |         int o = __builtin_popcount(mask);
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24916 KB Output is correct
2 Correct 15 ms 24908 KB Output is correct
3 Correct 12 ms 24916 KB Output is correct
4 Correct 12 ms 24948 KB Output is correct
5 Correct 13 ms 24916 KB Output is correct
6 Correct 13 ms 24916 KB Output is correct
7 Correct 14 ms 24956 KB Output is correct
8 Correct 12 ms 24916 KB Output is correct
9 Correct 14 ms 24868 KB Output is correct
10 Correct 12 ms 24868 KB Output is correct
11 Correct 11 ms 24916 KB Output is correct
12 Correct 13 ms 24916 KB Output is correct
13 Correct 13 ms 24916 KB Output is correct
14 Correct 14 ms 24916 KB Output is correct
15 Correct 14 ms 24916 KB Output is correct
16 Correct 13 ms 24916 KB Output is correct
17 Correct 13 ms 24840 KB Output is correct
18 Correct 15 ms 24824 KB Output is correct
19 Correct 13 ms 24872 KB Output is correct
20 Correct 13 ms 24872 KB Output is correct
21 Correct 14 ms 24916 KB Output is correct
22 Correct 13 ms 24916 KB Output is correct
23 Correct 13 ms 24916 KB Output is correct
24 Correct 12 ms 24944 KB Output is correct
25 Correct 12 ms 24916 KB Output is correct
26 Correct 13 ms 24848 KB Output is correct
27 Correct 12 ms 24916 KB Output is correct
28 Correct 14 ms 24936 KB Output is correct
29 Correct 12 ms 24916 KB Output is correct
30 Correct 12 ms 24924 KB Output is correct
31 Correct 14 ms 24848 KB Output is correct
32 Correct 12 ms 24820 KB Output is correct
33 Correct 12 ms 24916 KB Output is correct
34 Correct 13 ms 24916 KB Output is correct
35 Correct 12 ms 24916 KB Output is correct
36 Correct 12 ms 24900 KB Output is correct
37 Correct 13 ms 24916 KB Output is correct
38 Correct 12 ms 24916 KB Output is correct
39 Correct 13 ms 24916 KB Output is correct
40 Correct 12 ms 24940 KB Output is correct
41 Correct 12 ms 24916 KB Output is correct
42 Correct 11 ms 24916 KB Output is correct
43 Correct 12 ms 24916 KB Output is correct
44 Correct 12 ms 24832 KB Output is correct
45 Correct 12 ms 24828 KB Output is correct
46 Correct 12 ms 24832 KB Output is correct
47 Correct 12 ms 24916 KB Output is correct
48 Correct 12 ms 24916 KB Output is correct
49 Correct 12 ms 24896 KB Output is correct
50 Correct 12 ms 24916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24916 KB Output is correct
2 Correct 15 ms 24908 KB Output is correct
3 Correct 12 ms 24916 KB Output is correct
4 Correct 12 ms 24948 KB Output is correct
5 Correct 13 ms 24916 KB Output is correct
6 Correct 13 ms 24916 KB Output is correct
7 Correct 14 ms 24956 KB Output is correct
8 Correct 12 ms 24916 KB Output is correct
9 Correct 14 ms 24868 KB Output is correct
10 Correct 12 ms 24868 KB Output is correct
11 Correct 11 ms 24916 KB Output is correct
12 Correct 13 ms 24916 KB Output is correct
13 Correct 13 ms 24916 KB Output is correct
14 Correct 14 ms 24916 KB Output is correct
15 Correct 14 ms 24916 KB Output is correct
16 Correct 13 ms 24916 KB Output is correct
17 Correct 13 ms 24840 KB Output is correct
18 Correct 15 ms 24824 KB Output is correct
19 Correct 13 ms 24872 KB Output is correct
20 Correct 13 ms 24872 KB Output is correct
21 Correct 14 ms 24916 KB Output is correct
22 Correct 13 ms 24916 KB Output is correct
23 Correct 13 ms 24916 KB Output is correct
24 Correct 12 ms 24944 KB Output is correct
25 Correct 12 ms 24916 KB Output is correct
26 Correct 13 ms 24848 KB Output is correct
27 Correct 12 ms 24916 KB Output is correct
28 Correct 14 ms 24936 KB Output is correct
29 Correct 12 ms 24916 KB Output is correct
30 Correct 12 ms 24924 KB Output is correct
31 Correct 14 ms 24848 KB Output is correct
32 Correct 12 ms 24820 KB Output is correct
33 Correct 12 ms 24916 KB Output is correct
34 Correct 13 ms 24916 KB Output is correct
35 Correct 12 ms 24916 KB Output is correct
36 Correct 12 ms 24900 KB Output is correct
37 Correct 13 ms 24916 KB Output is correct
38 Correct 12 ms 24916 KB Output is correct
39 Correct 13 ms 24916 KB Output is correct
40 Correct 12 ms 24940 KB Output is correct
41 Correct 12 ms 24916 KB Output is correct
42 Correct 11 ms 24916 KB Output is correct
43 Correct 12 ms 24916 KB Output is correct
44 Correct 12 ms 24832 KB Output is correct
45 Correct 12 ms 24828 KB Output is correct
46 Correct 12 ms 24832 KB Output is correct
47 Correct 12 ms 24916 KB Output is correct
48 Correct 12 ms 24916 KB Output is correct
49 Correct 12 ms 24896 KB Output is correct
50 Correct 12 ms 24916 KB Output is correct
51 Correct 66 ms 24964 KB Output is correct
52 Correct 63 ms 24968 KB Output is correct
53 Correct 62 ms 24960 KB Output is correct
54 Correct 66 ms 24964 KB Output is correct
55 Correct 73 ms 24948 KB Output is correct
56 Correct 69 ms 24964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24916 KB Output is correct
2 Correct 146 ms 59496 KB Output is correct
3 Correct 165 ms 59552 KB Output is correct
4 Correct 121 ms 59424 KB Output is correct
5 Correct 140 ms 59416 KB Output is correct
6 Correct 122 ms 59556 KB Output is correct
7 Correct 149 ms 59456 KB Output is correct
8 Correct 12 ms 24916 KB Output is correct
9 Correct 13 ms 24924 KB Output is correct
10 Correct 13 ms 24916 KB Output is correct
11 Correct 12 ms 24916 KB Output is correct
12 Correct 11 ms 24952 KB Output is correct
13 Correct 12 ms 24952 KB Output is correct
14 Correct 12 ms 24880 KB Output is correct
15 Correct 13 ms 24916 KB Output is correct
16 Correct 12 ms 24916 KB Output is correct
17 Correct 63 ms 24872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24916 KB Output is correct
2 Correct 146 ms 59496 KB Output is correct
3 Correct 165 ms 59552 KB Output is correct
4 Correct 121 ms 59424 KB Output is correct
5 Correct 140 ms 59416 KB Output is correct
6 Correct 122 ms 59556 KB Output is correct
7 Correct 149 ms 59456 KB Output is correct
8 Correct 12 ms 24916 KB Output is correct
9 Correct 13 ms 24924 KB Output is correct
10 Correct 13 ms 24916 KB Output is correct
11 Correct 12 ms 24916 KB Output is correct
12 Correct 11 ms 24952 KB Output is correct
13 Correct 12 ms 24952 KB Output is correct
14 Correct 12 ms 24880 KB Output is correct
15 Correct 13 ms 24916 KB Output is correct
16 Correct 12 ms 24916 KB Output is correct
17 Correct 63 ms 24872 KB Output is correct
18 Correct 12 ms 24916 KB Output is correct
19 Correct 14 ms 24912 KB Output is correct
20 Incorrect 316 ms 59432 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24916 KB Output is correct
2 Correct 146 ms 59496 KB Output is correct
3 Correct 165 ms 59552 KB Output is correct
4 Correct 121 ms 59424 KB Output is correct
5 Correct 140 ms 59416 KB Output is correct
6 Correct 122 ms 59556 KB Output is correct
7 Correct 149 ms 59456 KB Output is correct
8 Correct 12 ms 24916 KB Output is correct
9 Correct 13 ms 24924 KB Output is correct
10 Correct 13 ms 24916 KB Output is correct
11 Correct 12 ms 24916 KB Output is correct
12 Correct 11 ms 24952 KB Output is correct
13 Correct 12 ms 24952 KB Output is correct
14 Correct 12 ms 24880 KB Output is correct
15 Correct 13 ms 24916 KB Output is correct
16 Correct 12 ms 24916 KB Output is correct
17 Correct 63 ms 24872 KB Output is correct
18 Correct 12 ms 24916 KB Output is correct
19 Correct 14 ms 24912 KB Output is correct
20 Incorrect 316 ms 59432 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24916 KB Output is correct
2 Correct 146 ms 59496 KB Output is correct
3 Correct 165 ms 59552 KB Output is correct
4 Correct 121 ms 59424 KB Output is correct
5 Correct 140 ms 59416 KB Output is correct
6 Correct 122 ms 59556 KB Output is correct
7 Correct 149 ms 59456 KB Output is correct
8 Correct 12 ms 24916 KB Output is correct
9 Correct 13 ms 24924 KB Output is correct
10 Correct 13 ms 24916 KB Output is correct
11 Correct 12 ms 24916 KB Output is correct
12 Correct 11 ms 24952 KB Output is correct
13 Correct 12 ms 24952 KB Output is correct
14 Correct 12 ms 24880 KB Output is correct
15 Correct 13 ms 24916 KB Output is correct
16 Correct 12 ms 24916 KB Output is correct
17 Correct 63 ms 24872 KB Output is correct
18 Correct 12 ms 24916 KB Output is correct
19 Correct 14 ms 24912 KB Output is correct
20 Incorrect 316 ms 59432 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24916 KB Output is correct
2 Correct 15 ms 24908 KB Output is correct
3 Correct 12 ms 24916 KB Output is correct
4 Correct 12 ms 24948 KB Output is correct
5 Correct 13 ms 24916 KB Output is correct
6 Correct 13 ms 24916 KB Output is correct
7 Correct 14 ms 24956 KB Output is correct
8 Correct 12 ms 24916 KB Output is correct
9 Correct 14 ms 24868 KB Output is correct
10 Correct 12 ms 24868 KB Output is correct
11 Correct 11 ms 24916 KB Output is correct
12 Correct 13 ms 24916 KB Output is correct
13 Correct 13 ms 24916 KB Output is correct
14 Correct 14 ms 24916 KB Output is correct
15 Correct 14 ms 24916 KB Output is correct
16 Correct 13 ms 24916 KB Output is correct
17 Correct 13 ms 24840 KB Output is correct
18 Correct 15 ms 24824 KB Output is correct
19 Correct 13 ms 24872 KB Output is correct
20 Correct 13 ms 24872 KB Output is correct
21 Correct 14 ms 24916 KB Output is correct
22 Correct 13 ms 24916 KB Output is correct
23 Correct 13 ms 24916 KB Output is correct
24 Correct 12 ms 24944 KB Output is correct
25 Correct 12 ms 24916 KB Output is correct
26 Correct 13 ms 24848 KB Output is correct
27 Correct 12 ms 24916 KB Output is correct
28 Correct 14 ms 24936 KB Output is correct
29 Correct 12 ms 24916 KB Output is correct
30 Correct 12 ms 24924 KB Output is correct
31 Correct 14 ms 24848 KB Output is correct
32 Correct 12 ms 24820 KB Output is correct
33 Correct 12 ms 24916 KB Output is correct
34 Correct 13 ms 24916 KB Output is correct
35 Correct 12 ms 24916 KB Output is correct
36 Correct 12 ms 24900 KB Output is correct
37 Correct 13 ms 24916 KB Output is correct
38 Correct 12 ms 24916 KB Output is correct
39 Correct 13 ms 24916 KB Output is correct
40 Correct 12 ms 24940 KB Output is correct
41 Correct 12 ms 24916 KB Output is correct
42 Correct 11 ms 24916 KB Output is correct
43 Correct 12 ms 24916 KB Output is correct
44 Correct 12 ms 24832 KB Output is correct
45 Correct 12 ms 24828 KB Output is correct
46 Correct 12 ms 24832 KB Output is correct
47 Correct 12 ms 24916 KB Output is correct
48 Correct 12 ms 24916 KB Output is correct
49 Correct 12 ms 24896 KB Output is correct
50 Correct 12 ms 24916 KB Output is correct
51 Correct 66 ms 24964 KB Output is correct
52 Correct 63 ms 24968 KB Output is correct
53 Correct 62 ms 24960 KB Output is correct
54 Correct 66 ms 24964 KB Output is correct
55 Correct 73 ms 24948 KB Output is correct
56 Correct 69 ms 24964 KB Output is correct
57 Correct 12 ms 24916 KB Output is correct
58 Correct 146 ms 59496 KB Output is correct
59 Correct 165 ms 59552 KB Output is correct
60 Correct 121 ms 59424 KB Output is correct
61 Correct 140 ms 59416 KB Output is correct
62 Correct 122 ms 59556 KB Output is correct
63 Correct 149 ms 59456 KB Output is correct
64 Correct 12 ms 24916 KB Output is correct
65 Correct 13 ms 24924 KB Output is correct
66 Correct 13 ms 24916 KB Output is correct
67 Correct 12 ms 24916 KB Output is correct
68 Correct 11 ms 24952 KB Output is correct
69 Correct 12 ms 24952 KB Output is correct
70 Correct 12 ms 24880 KB Output is correct
71 Correct 13 ms 24916 KB Output is correct
72 Correct 12 ms 24916 KB Output is correct
73 Correct 63 ms 24872 KB Output is correct
74 Correct 12 ms 24916 KB Output is correct
75 Correct 14 ms 24912 KB Output is correct
76 Incorrect 316 ms 59432 KB Output isn't correct
77 Halted 0 ms 0 KB -