#include <bits/stdc++.h>
using namespace std;
#define ll int
#define pll pair<int, int>
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
const ll N = 2e6 + 100;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
const ll block = 350;
ll n,m;
ll a[N][21], res[N], cnt[N], dp[N], mp[N];
pll mn[N];
void to_thic_cau(){
cin >> n >> m;
for(int i = 0; i < (1 << m);i++) mn[i] = {inf, inf};
for(int i = 1; i <= n;i++){
ll msk = 0;
for(int j = 0; j < m;j++){
cin >> a[i][j];
if(a[i][j] == 1) cnt[j]++, msk |= (1 << j);
}
dp[msk]++;
mp[msk]++;
}
for(int i = 0; i < m;i++){
for(int msk = 0; msk < (1 << m);msk++) if(msk & (1 << i)) dp[msk] += dp[msk ^ (1 << i)];
}
for(int msk = 0; msk < (1 << m);msk++){
ll inv_msk = ((1 << m) - 1) ^ msk;
for(int sub = msk; sub >= 0;sub = (sub - 1) & msk){
ll cur = sub | inv_msk;
ll c = __builtin_popcount(sub);
ll d = 0;
for(int final_msk = cur; final_msk >= 0; final_msk = (final_msk - 1) & cur){
if(((final_msk) & sub) == sub) d += mp[final_msk];
if(final_msk == 0) break;
}
if(d >= 1){
if(c < mn[msk].F) mn[msk].S = mn[msk].F, mn[msk].F = c;
else if(c < mn[msk].S) mn[msk].S = c;
}
if(d >= 2){
mn[msk].F = min(mn[msk].F, c); mn[msk].S = min(mn[msk].S, c);
}
if(sub == 0) break;
}
}
for(int i = 1; i <= n;i++){
ll msk = 0, cur = 0, res = 0;
for(int j = 0; j < m;j++){
if(a[i][j] == 1) cnt[j]--;
if(cnt[j] == n / 2) msk |= (1 << j), res++;
else if(cnt[j] > n / 2) res++;
}
for(int j = 0; j < m;j++) if((msk & (1 << j)) && a[i][j] == 1) cur++;
if(cur == mn[msk].F) res -= mn[msk].S;
else res -= mn[msk].F;
for(int j = 0; j < m;j++) if(a[i][j] == 1) cnt[j]++;
cout << res << "\n";
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tc = 1;
//cin >> tc;
while(tc--) to_thic_cau();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
197 ms |
524 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Execution timed out |
4100 ms |
12804 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
197 ms |
524 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Execution timed out |
4100 ms |
12804 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
43 ms |
26716 KB |
Output is correct |
3 |
Correct |
46 ms |
26724 KB |
Output is correct |
4 |
Correct |
36 ms |
26196 KB |
Output is correct |
5 |
Correct |
58 ms |
26708 KB |
Output is correct |
6 |
Correct |
36 ms |
26204 KB |
Output is correct |
7 |
Correct |
50 ms |
26748 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
43 ms |
26716 KB |
Output is correct |
3 |
Correct |
46 ms |
26724 KB |
Output is correct |
4 |
Correct |
36 ms |
26196 KB |
Output is correct |
5 |
Correct |
58 ms |
26708 KB |
Output is correct |
6 |
Correct |
36 ms |
26204 KB |
Output is correct |
7 |
Correct |
50 ms |
26748 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
163 ms |
31444 KB |
Output is correct |
21 |
Correct |
146 ms |
31020 KB |
Output is correct |
22 |
Correct |
144 ms |
30804 KB |
Output is correct |
23 |
Correct |
137 ms |
31828 KB |
Output is correct |
24 |
Correct |
142 ms |
31568 KB |
Output is correct |
25 |
Correct |
176 ms |
31568 KB |
Output is correct |
26 |
Correct |
177 ms |
31572 KB |
Output is correct |
27 |
Correct |
9 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
2 ms |
348 KB |
Output is correct |
35 |
Correct |
9 ms |
512 KB |
Output is correct |
36 |
Correct |
9 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
488 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
348 KB |
Output is correct |
44 |
Correct |
9 ms |
348 KB |
Output is correct |
45 |
Correct |
9 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
43 ms |
26716 KB |
Output is correct |
3 |
Correct |
46 ms |
26724 KB |
Output is correct |
4 |
Correct |
36 ms |
26196 KB |
Output is correct |
5 |
Correct |
58 ms |
26708 KB |
Output is correct |
6 |
Correct |
36 ms |
26204 KB |
Output is correct |
7 |
Correct |
50 ms |
26748 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
163 ms |
31444 KB |
Output is correct |
21 |
Correct |
146 ms |
31020 KB |
Output is correct |
22 |
Correct |
144 ms |
30804 KB |
Output is correct |
23 |
Correct |
137 ms |
31828 KB |
Output is correct |
24 |
Correct |
142 ms |
31568 KB |
Output is correct |
25 |
Correct |
176 ms |
31568 KB |
Output is correct |
26 |
Correct |
177 ms |
31572 KB |
Output is correct |
27 |
Correct |
9 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
2 ms |
348 KB |
Output is correct |
35 |
Correct |
9 ms |
512 KB |
Output is correct |
36 |
Correct |
9 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
488 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
348 KB |
Output is correct |
44 |
Correct |
9 ms |
348 KB |
Output is correct |
45 |
Correct |
9 ms |
460 KB |
Output is correct |
46 |
Correct |
190 ms |
344 KB |
Output is correct |
47 |
Execution timed out |
4067 ms |
33364 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
43 ms |
26716 KB |
Output is correct |
3 |
Correct |
46 ms |
26724 KB |
Output is correct |
4 |
Correct |
36 ms |
26196 KB |
Output is correct |
5 |
Correct |
58 ms |
26708 KB |
Output is correct |
6 |
Correct |
36 ms |
26204 KB |
Output is correct |
7 |
Correct |
50 ms |
26748 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
163 ms |
31444 KB |
Output is correct |
21 |
Correct |
146 ms |
31020 KB |
Output is correct |
22 |
Correct |
144 ms |
30804 KB |
Output is correct |
23 |
Correct |
137 ms |
31828 KB |
Output is correct |
24 |
Correct |
142 ms |
31568 KB |
Output is correct |
25 |
Correct |
176 ms |
31568 KB |
Output is correct |
26 |
Correct |
177 ms |
31572 KB |
Output is correct |
27 |
Correct |
9 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
2 ms |
348 KB |
Output is correct |
35 |
Correct |
9 ms |
512 KB |
Output is correct |
36 |
Correct |
9 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
488 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
348 KB |
Output is correct |
44 |
Correct |
9 ms |
348 KB |
Output is correct |
45 |
Correct |
9 ms |
460 KB |
Output is correct |
46 |
Correct |
190 ms |
344 KB |
Output is correct |
47 |
Execution timed out |
4067 ms |
33364 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
197 ms |
524 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Execution timed out |
4100 ms |
12804 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |