답안 #768849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768849 2023-06-28T18:34:49 Z danikoynov Council (JOI23_council) C++14
41 / 100
4000 ms 13588 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 << 11)][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 <= 10)
    {
        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;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 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 1 ms 212 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 0 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 212 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 0 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 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 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 340 KB Output is correct
40 Correct 1 ms 296 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 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 1 ms 212 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 0 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 212 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 0 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 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 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 340 KB Output is correct
40 Correct 1 ms 296 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 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 160 ms 376 KB Output is correct
52 Correct 139 ms 340 KB Output is correct
53 Correct 135 ms 376 KB Output is correct
54 Correct 160 ms 380 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 139 ms 372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 55 ms 6984 KB Output is correct
3 Correct 51 ms 7964 KB Output is correct
4 Correct 38 ms 7472 KB Output is correct
5 Correct 54 ms 8024 KB Output is correct
6 Correct 43 ms 7516 KB Output is correct
7 Correct 59 ms 8028 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 55 ms 6984 KB Output is correct
3 Correct 51 ms 7964 KB Output is correct
4 Correct 38 ms 7472 KB Output is correct
5 Correct 54 ms 8024 KB Output is correct
6 Correct 43 ms 7516 KB Output is correct
7 Correct 59 ms 8028 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 324 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 910 ms 11980 KB Output is correct
21 Correct 515 ms 11132 KB Output is correct
22 Correct 513 ms 11412 KB Output is correct
23 Correct 848 ms 12280 KB Output is correct
24 Correct 838 ms 11844 KB Output is correct
25 Correct 862 ms 12052 KB Output is correct
26 Correct 864 ms 12072 KB Output is correct
27 Correct 1 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 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 1 ms 212 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 1 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 1 ms 340 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 55 ms 6984 KB Output is correct
3 Correct 51 ms 7964 KB Output is correct
4 Correct 38 ms 7472 KB Output is correct
5 Correct 54 ms 8024 KB Output is correct
6 Correct 43 ms 7516 KB Output is correct
7 Correct 59 ms 8028 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 324 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 910 ms 11980 KB Output is correct
21 Correct 515 ms 11132 KB Output is correct
22 Correct 513 ms 11412 KB Output is correct
23 Correct 848 ms 12280 KB Output is correct
24 Correct 838 ms 11844 KB Output is correct
25 Correct 862 ms 12052 KB Output is correct
26 Correct 864 ms 12072 KB Output is correct
27 Correct 1 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 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 1 ms 212 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 1 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 1 ms 340 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Execution timed out 4049 ms 13588 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 55 ms 6984 KB Output is correct
3 Correct 51 ms 7964 KB Output is correct
4 Correct 38 ms 7472 KB Output is correct
5 Correct 54 ms 8024 KB Output is correct
6 Correct 43 ms 7516 KB Output is correct
7 Correct 59 ms 8028 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 324 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 910 ms 11980 KB Output is correct
21 Correct 515 ms 11132 KB Output is correct
22 Correct 513 ms 11412 KB Output is correct
23 Correct 848 ms 12280 KB Output is correct
24 Correct 838 ms 11844 KB Output is correct
25 Correct 862 ms 12052 KB Output is correct
26 Correct 864 ms 12072 KB Output is correct
27 Correct 1 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 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 1 ms 212 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 1 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 1 ms 340 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Execution timed out 4049 ms 13588 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 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 1 ms 212 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 0 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 212 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 0 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 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 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 340 KB Output is correct
40 Correct 1 ms 296 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 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 160 ms 376 KB Output is correct
52 Correct 139 ms 340 KB Output is correct
53 Correct 135 ms 376 KB Output is correct
54 Correct 160 ms 380 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 139 ms 372 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 55 ms 6984 KB Output is correct
59 Correct 51 ms 7964 KB Output is correct
60 Correct 38 ms 7472 KB Output is correct
61 Correct 54 ms 8024 KB Output is correct
62 Correct 43 ms 7516 KB Output is correct
63 Correct 59 ms 8028 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 1 ms 324 KB Output is correct
69 Correct 1 ms 328 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 324 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 910 ms 11980 KB Output is correct
77 Correct 515 ms 11132 KB Output is correct
78 Correct 513 ms 11412 KB Output is correct
79 Correct 848 ms 12280 KB Output is correct
80 Correct 838 ms 11844 KB Output is correct
81 Correct 862 ms 12052 KB Output is correct
82 Correct 864 ms 12072 KB Output is correct
83 Correct 1 ms 212 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 1 ms 212 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 1 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 1 ms 340 KB Output is correct
100 Correct 1 ms 212 KB Output is correct
101 Correct 1 ms 340 KB Output is correct
102 Correct 0 ms 212 KB Output is correct
103 Execution timed out 4049 ms 13588 KB Time limit exceeded
104 Halted 0 ms 0 KB -