Submission #768854

# Submission time Handle Problem Language Result Execution time Memory
768854 2023-06-28T19:06:30 Z danikoynov Council (JOI23_council) C++14
41 / 100
4000 ms 7372 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
 
**/
 
#include<bits/stdc++.h>
#define endl '\n'
 
using namespace std;
typedef long long ll;
 
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const int maxn = 3e5 + 10, maxm = 21;
int n, m, imp[maxm], cnt[maxm];
bool a[maxn][maxm];
int dp[(1 << 15)][2];
void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i ++)
        for (int j = 0; j < m; j ++)
            cin >> a[i][j], cnt[j] += a[i][j];
    if (m <= 14)
    {
        for (int mask = 0; mask < (1 << m); mask ++)
            dp[mask][0] = dp[mask][1] = -1;
        for (int i = 1; i <= n; i ++)
        {
            int can_mask = 0;
            for (int j = m - 1; j >= 0; j --)
                can_mask = can_mask * 2 + (1 - a[i][j]);
            for (int mask = 0; mask < (1 << m); mask ++)
            {
                int sub = (mask & can_mask);
                int val = __builtin_popcount(sub);
                ///cout << i << " ---- " << mask << " " << val << endl;
                if (val > dp[mask][0])
                {
                    dp[mask][1] = dp[mask][0];
                    ///cout << "trans" << " " << val << endl;
                    dp[mask][0] = val;
                    ///cout << "here " << mask << " " << dp[mask][0] << " " << val << endl;
                }
                else if (val > dp[mask][1])
                {
                    dp[mask][1] = val;
                }
            }
        }
 
        for (int i = 1; i <= n; i ++)
        {
            int base = 0;
            for (int j = 0; j < m; j ++)
            {
                int cur = cnt[j] - a[i][j];
                if (cur >= n / 2)
                {
                    if ((cur - 1) < n / 2)
                        imp[j] = 1;
                    else
                        imp[j] = 0, base ++;
                }
                else
                {
                    imp[j] = 0;
                }
 
            }
 
 
            int mask = 0;
            for (int bit = m - 1; bit >= 0; bit --)
                mask = mask * 2 + imp[bit];
            int can_mask = 0;
            for (int j = m - 1; j >= 0; j --)
                can_mask = can_mask * 2 + (1 - a[i][j]);
            int val = __builtin_popcount((can_mask & mask));
            //cout << i << " : " << val << " " << can_mask << " :: " << mask << endl;
            //cout << dp[mask][0] << " " << dp[mask][1] << endl;
            int best = dp[mask][0];
            if (val == best)
                best = dp[mask][1];
            cout << base + best << endl;
 
 
        }
    }
    else
    {
 
        for (int i = 1; i <= n; i ++)
        {
            int base = 0;
            for (int j = 0; j < m; j ++)
            {
                int cur = cnt[j] - a[i][j];
                if (cur >= n / 2)
                {
                    if ((cur - 1) < n / 2)
                        imp[j] = 1;
                    else
                        imp[j] = 0, base ++;
                }
                else
                {
                    imp[j] = 0;
                }
 
            }
 
            /**cout << "----" << endl;
            cout << i << endl;
            for (int bit = 0; bit < m; bit ++)
                cout << imp[bit] << " ";
            cout << endl;*/
            int best = -m;
            for (int p = 1; p <= n; p ++)
            {
                if (p == i)
                    continue;
                int sum = 0;
                for (int bit = 0; bit < m; bit ++)
                {
                    if (imp[bit] == 1)
                    {
                        if (a[p][bit] == 0)
                            sum ++;
                    }
                }
 
                best = max(best, sum);
            }
 
            cout << base + best << endl;
 
 
        }
    }
}
 
int main()
{
    speed();
    solve();
    return 0;
}
 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 424 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 424 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 133 ms 384 KB Output is correct
52 Correct 143 ms 384 KB Output is correct
53 Correct 130 ms 380 KB Output is correct
54 Correct 164 ms 384 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 137 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 56 ms 7044 KB Output is correct
3 Correct 49 ms 7060 KB Output is correct
4 Correct 37 ms 7004 KB Output is correct
5 Correct 54 ms 6992 KB Output is correct
6 Correct 40 ms 7052 KB Output is correct
7 Correct 68 ms 7016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 56 ms 7044 KB Output is correct
3 Correct 49 ms 7060 KB Output is correct
4 Correct 37 ms 7004 KB Output is correct
5 Correct 54 ms 6992 KB Output is correct
6 Correct 40 ms 7052 KB Output is correct
7 Correct 68 ms 7016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 858 ms 7076 KB Output is correct
21 Correct 506 ms 6988 KB Output is correct
22 Correct 529 ms 6984 KB Output is correct
23 Correct 841 ms 7372 KB Output is correct
24 Correct 826 ms 6988 KB Output is correct
25 Correct 890 ms 6992 KB Output is correct
26 Correct 860 ms 6984 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 56 ms 7044 KB Output is correct
3 Correct 49 ms 7060 KB Output is correct
4 Correct 37 ms 7004 KB Output is correct
5 Correct 54 ms 6992 KB Output is correct
6 Correct 40 ms 7052 KB Output is correct
7 Correct 68 ms 7016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 858 ms 7076 KB Output is correct
21 Correct 506 ms 6988 KB Output is correct
22 Correct 529 ms 6984 KB Output is correct
23 Correct 841 ms 7372 KB Output is correct
24 Correct 826 ms 6988 KB Output is correct
25 Correct 890 ms 6992 KB Output is correct
26 Correct 860 ms 6984 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Execution timed out 4072 ms 6548 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 56 ms 7044 KB Output is correct
3 Correct 49 ms 7060 KB Output is correct
4 Correct 37 ms 7004 KB Output is correct
5 Correct 54 ms 6992 KB Output is correct
6 Correct 40 ms 7052 KB Output is correct
7 Correct 68 ms 7016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 858 ms 7076 KB Output is correct
21 Correct 506 ms 6988 KB Output is correct
22 Correct 529 ms 6984 KB Output is correct
23 Correct 841 ms 7372 KB Output is correct
24 Correct 826 ms 6988 KB Output is correct
25 Correct 890 ms 6992 KB Output is correct
26 Correct 860 ms 6984 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Execution timed out 4072 ms 6548 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 424 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 133 ms 384 KB Output is correct
52 Correct 143 ms 384 KB Output is correct
53 Correct 130 ms 380 KB Output is correct
54 Correct 164 ms 384 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 137 ms 384 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 56 ms 7044 KB Output is correct
59 Correct 49 ms 7060 KB Output is correct
60 Correct 37 ms 7004 KB Output is correct
61 Correct 54 ms 6992 KB Output is correct
62 Correct 40 ms 7052 KB Output is correct
63 Correct 68 ms 7016 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 0 ms 212 KB Output is correct
69 Correct 0 ms 212 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 858 ms 7076 KB Output is correct
77 Correct 506 ms 6988 KB Output is correct
78 Correct 529 ms 6984 KB Output is correct
79 Correct 841 ms 7372 KB Output is correct
80 Correct 826 ms 6988 KB Output is correct
81 Correct 890 ms 6992 KB Output is correct
82 Correct 860 ms 6984 KB Output is correct
83 Correct 0 ms 340 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 0 ms 212 KB Output is correct
86 Correct 0 ms 212 KB Output is correct
87 Correct 1 ms 340 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 0 ms 212 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 340 KB Output is correct
92 Correct 1 ms 340 KB Output is correct
93 Correct 0 ms 212 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 1 ms 212 KB Output is correct
98 Correct 0 ms 212 KB Output is correct
99 Correct 0 ms 340 KB Output is correct
100 Correct 0 ms 212 KB Output is correct
101 Correct 1 ms 340 KB Output is correct
102 Correct 0 ms 340 KB Output is correct
103 Execution timed out 4072 ms 6548 KB Time limit exceeded
104 Halted 0 ms 0 KB -