#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 3e5+10;
const int B = 15;
int arr[mxn];
int dp[1<<B];
int N,M;
int cnt[mxn];
int f(int id){
for(int i = 0;i<M;i++){
if((1<<i)&arr[id])cnt[i]--;
}
dp[arr[id]]--;
int mask = 0,ans = 0;
for(int i = 0;i<M;i++){
if(cnt[i] == N/2)mask|=1<<i;
if(cnt[i] >= N/2)ans++;
}
int c = B;
for(int i = 0;i<(1<<M);i++)if(dp[i])c = min(c,__builtin_popcount(mask&i));
ans -= c;
for(int i = 0;i<M;i++)if((1<<i)&arr[id])cnt[i]++;
dp[arr[id]]++;
return ans;
}
namespace SPEC{
void GO(){
for(int id = 1;id<=N;id++){
for(int i = 0;i<M;i++){
if((1<<i)&arr[id])cnt[i]--;
}
int mask = 0,ans = 0;
for(int i = 0;i<M;i++){
if(cnt[i] == N/2)mask|=1<<i;
if(cnt[i] >= N/2)ans++;
}
int c = B;
for(int i = 1;i<=N;i++)if(i != id)c = min(c,__builtin_popcount(mask&arr[i]));
ans -= c;
for(int i = 0;i<M;i++)if((1<<i)&arr[id])cnt[i]++;
dp[arr[id]]++;
cout<<ans<<'\n';
}
return;
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>M;
for(int i = 1;i<=N;i++){
for(int j = 0;j<M;j++){
int k;
cin>>k;
if(k)cnt[j]++,arr[i]|=1<<j;
}
dp[arr[i]]++;
}
if(N<=5000){
SPEC::GO();
return 0;
}
for(int i = 1;i<=N;i++)cout<<f(i)<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Runtime error |
2 ms |
4700 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Runtime error |
2 ms |
4700 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
51 ms |
3164 KB |
Output is correct |
3 |
Correct |
63 ms |
3016 KB |
Output is correct |
4 |
Correct |
38 ms |
3208 KB |
Output is correct |
5 |
Correct |
40 ms |
3156 KB |
Output is correct |
6 |
Correct |
27 ms |
3160 KB |
Output is correct |
7 |
Correct |
40 ms |
3156 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
8 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
51 ms |
3164 KB |
Output is correct |
3 |
Correct |
63 ms |
3016 KB |
Output is correct |
4 |
Correct |
38 ms |
3208 KB |
Output is correct |
5 |
Correct |
40 ms |
3156 KB |
Output is correct |
6 |
Correct |
27 ms |
3160 KB |
Output is correct |
7 |
Correct |
40 ms |
3156 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
8 ms |
2648 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
329 ms |
2384 KB |
Output is correct |
21 |
Correct |
197 ms |
5968 KB |
Output is correct |
22 |
Correct |
216 ms |
5968 KB |
Output is correct |
23 |
Correct |
280 ms |
6480 KB |
Output is correct |
24 |
Correct |
268 ms |
6072 KB |
Output is correct |
25 |
Correct |
386 ms |
6320 KB |
Output is correct |
26 |
Correct |
352 ms |
6188 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2516 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2516 KB |
Output is correct |
35 |
Correct |
1 ms |
2504 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
0 ms |
2512 KB |
Output is correct |
38 |
Correct |
0 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2508 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2524 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
51 ms |
3164 KB |
Output is correct |
3 |
Correct |
63 ms |
3016 KB |
Output is correct |
4 |
Correct |
38 ms |
3208 KB |
Output is correct |
5 |
Correct |
40 ms |
3156 KB |
Output is correct |
6 |
Correct |
27 ms |
3160 KB |
Output is correct |
7 |
Correct |
40 ms |
3156 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
8 ms |
2648 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
329 ms |
2384 KB |
Output is correct |
21 |
Correct |
197 ms |
5968 KB |
Output is correct |
22 |
Correct |
216 ms |
5968 KB |
Output is correct |
23 |
Correct |
280 ms |
6480 KB |
Output is correct |
24 |
Correct |
268 ms |
6072 KB |
Output is correct |
25 |
Correct |
386 ms |
6320 KB |
Output is correct |
26 |
Correct |
352 ms |
6188 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2516 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2516 KB |
Output is correct |
35 |
Correct |
1 ms |
2504 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
0 ms |
2512 KB |
Output is correct |
38 |
Correct |
0 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2508 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2524 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
0 ms |
2396 KB |
Output is correct |
47 |
Correct |
2502 ms |
7592 KB |
Output is correct |
48 |
Correct |
1311 ms |
7328 KB |
Output is correct |
49 |
Correct |
1340 ms |
7252 KB |
Output is correct |
50 |
Correct |
2201 ms |
7824 KB |
Output is correct |
51 |
Correct |
2043 ms |
7356 KB |
Output is correct |
52 |
Correct |
3273 ms |
7652 KB |
Output is correct |
53 |
Correct |
3127 ms |
7900 KB |
Output is correct |
54 |
Correct |
1 ms |
2392 KB |
Output is correct |
55 |
Correct |
1 ms |
2396 KB |
Output is correct |
56 |
Correct |
0 ms |
2396 KB |
Output is correct |
57 |
Correct |
0 ms |
2396 KB |
Output is correct |
58 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
51 ms |
3164 KB |
Output is correct |
3 |
Correct |
63 ms |
3016 KB |
Output is correct |
4 |
Correct |
38 ms |
3208 KB |
Output is correct |
5 |
Correct |
40 ms |
3156 KB |
Output is correct |
6 |
Correct |
27 ms |
3160 KB |
Output is correct |
7 |
Correct |
40 ms |
3156 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
8 ms |
2648 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
329 ms |
2384 KB |
Output is correct |
21 |
Correct |
197 ms |
5968 KB |
Output is correct |
22 |
Correct |
216 ms |
5968 KB |
Output is correct |
23 |
Correct |
280 ms |
6480 KB |
Output is correct |
24 |
Correct |
268 ms |
6072 KB |
Output is correct |
25 |
Correct |
386 ms |
6320 KB |
Output is correct |
26 |
Correct |
352 ms |
6188 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2516 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2516 KB |
Output is correct |
35 |
Correct |
1 ms |
2504 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
0 ms |
2512 KB |
Output is correct |
38 |
Correct |
0 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2508 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2524 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
0 ms |
2396 KB |
Output is correct |
47 |
Correct |
2502 ms |
7592 KB |
Output is correct |
48 |
Correct |
1311 ms |
7328 KB |
Output is correct |
49 |
Correct |
1340 ms |
7252 KB |
Output is correct |
50 |
Correct |
2201 ms |
7824 KB |
Output is correct |
51 |
Correct |
2043 ms |
7356 KB |
Output is correct |
52 |
Correct |
3273 ms |
7652 KB |
Output is correct |
53 |
Correct |
3127 ms |
7900 KB |
Output is correct |
54 |
Correct |
1 ms |
2392 KB |
Output is correct |
55 |
Correct |
1 ms |
2396 KB |
Output is correct |
56 |
Correct |
0 ms |
2396 KB |
Output is correct |
57 |
Correct |
0 ms |
2396 KB |
Output is correct |
58 |
Correct |
0 ms |
2396 KB |
Output is correct |
59 |
Execution timed out |
4022 ms |
7852 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Runtime error |
2 ms |
4700 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |