#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
#define pii pair<int,int>
#define ff first
#define ss second
const int M = (1<<20)+5;
const int N = 300005;
pair<int,int> dis[M][2];
bool vote[N][20];
int ans[M];
int rs = 0;
int n,m;
int care[20];
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=0;i<(1<<m);i++){
for(int b=0;b<2;b++) dis[i][b] = {1e9,-1};
}
queue<pii > q;
for(int i=0;i<n;i++){
int s=0;
for(int j=0;j<m;j++){
cin>>vote[i][j];
if(vote[i][j]) s+=(1<<j);
}
if(dis[s][0].ff!=1e9){
dis[s][1] = {0,i};
q.push({s,1});
}else{
dis[s][0] = {0,i};
q.push({s,0});
}
}
int base=0;
for(int i=0;i<m;i++){
int cnt = 0;
for(int j=0;j<n;j++) if(vote[j][i]) cnt++;
care[i]=0;
if(cnt==(n/2)){
care[i]=1;
}else if(cnt==(n/2)+1){
care[i]=2;
}else if(cnt>=(n/2)+2) base++;
}
while(q.size()){
pii cur = q.front();
q.pop();
for(int j=0;j<m;j++){
int c= cur.ff^(1<<j);
if(dis[c][0].ff>dis[cur.ff][cur.ss].ff+1){
dis[c][0] = {dis[cur.ff][cur.ss].ff+1, dis[cur.ff][cur.ss].ss};
q.push({c,0});
}else if(dis[c][1].ff>dis[cur.ff][cur.ss].ff+1 && dis[c][0].ss!=dis[cur.ff][cur.ss].ss){
dis[c][1] = {dis[cur.ff][cur.ss].ff+1,dis[cur.ff][cur.ss].ss};
q.push({c,0});
}
}
//for(int i=0;i<(1<<m);i++) cout<<dis[i][0].ff<<","<<dis[i][0].ss<<" "<<dis[i][1].ff<<","<<dis[i][1].ss<<"|\n"[(i%4==3)];
//cout<<"\n\n\n";
}
for(int j=0;j<m;j++){
for(int i=0;i<(1<<m);i++){
if((i>>j)&1){
int c = i^(1<<j);
if(dis[i][1].ff<dis[c][0].ff) continue;
if(dis[i][0].ff>dis[c][1].ff){
dis[i][0] = dis[c][0];
dis[i][1] = dis[c][1];
continue;
}
if(dis[i][0].ss!=dis[c][0].ss){
if(dis[i][0].ff<dis[c][0].ff) dis[i][1] = dis[c][0];
else{
dis[i][1] = dis[i][0];
dis[i][0] = dis[c][0];
}
}else{
dis[i][0] = min(dis[i][0],dis[c][0]);
dis[i][1] = min(dis[i][1],dis[c][1]);
}
}
}
}
for(int i=0;i<n;i++){
int re = base;
int s=0;
int posi=0;
for(int j=0;j<m;j++){
if(vote[i][j]!=care[j]-1) s+=(1<<j);
else posi++;
if(care[j]==2 && vote[i][j]==0) re++;
}
if(dis[s][0].ss==i) posi-=dis[s][1].ff;
else posi-=dis[s][0].ff;
cout<<re+posi<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
283 ms |
25300 KB |
Output is correct |
6 |
Correct |
207 ms |
22096 KB |
Output is correct |
7 |
Correct |
315 ms |
24300 KB |
Output is correct |
8 |
Correct |
384 ms |
26396 KB |
Output is correct |
9 |
Correct |
406 ms |
29404 KB |
Output is correct |
10 |
Correct |
341 ms |
25072 KB |
Output is correct |
11 |
Correct |
393 ms |
26580 KB |
Output is correct |
12 |
Correct |
400 ms |
29500 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4704 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4440 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4556 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
2 ms |
4444 KB |
Output is correct |
42 |
Correct |
3 ms |
4560 KB |
Output is correct |
43 |
Correct |
4 ms |
4444 KB |
Output is correct |
44 |
Correct |
3 ms |
4444 KB |
Output is correct |
45 |
Correct |
4 ms |
4700 KB |
Output is correct |
46 |
Correct |
22 ms |
7224 KB |
Output is correct |
47 |
Correct |
27 ms |
7124 KB |
Output is correct |
48 |
Correct |
33 ms |
7260 KB |
Output is correct |
49 |
Correct |
26 ms |
7260 KB |
Output is correct |
50 |
Correct |
32 ms |
7496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
283 ms |
25300 KB |
Output is correct |
6 |
Correct |
207 ms |
22096 KB |
Output is correct |
7 |
Correct |
315 ms |
24300 KB |
Output is correct |
8 |
Correct |
384 ms |
26396 KB |
Output is correct |
9 |
Correct |
406 ms |
29404 KB |
Output is correct |
10 |
Correct |
341 ms |
25072 KB |
Output is correct |
11 |
Correct |
393 ms |
26580 KB |
Output is correct |
12 |
Correct |
400 ms |
29500 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4704 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4440 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4556 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
2 ms |
4444 KB |
Output is correct |
42 |
Correct |
3 ms |
4560 KB |
Output is correct |
43 |
Correct |
4 ms |
4444 KB |
Output is correct |
44 |
Correct |
3 ms |
4444 KB |
Output is correct |
45 |
Correct |
4 ms |
4700 KB |
Output is correct |
46 |
Correct |
22 ms |
7224 KB |
Output is correct |
47 |
Correct |
27 ms |
7124 KB |
Output is correct |
48 |
Correct |
33 ms |
7260 KB |
Output is correct |
49 |
Correct |
26 ms |
7260 KB |
Output is correct |
50 |
Correct |
32 ms |
7496 KB |
Output is correct |
51 |
Correct |
192 ms |
22100 KB |
Output is correct |
52 |
Correct |
177 ms |
22100 KB |
Output is correct |
53 |
Correct |
404 ms |
32052 KB |
Output is correct |
54 |
Correct |
396 ms |
31920 KB |
Output is correct |
55 |
Correct |
1 ms |
4644 KB |
Output is correct |
56 |
Correct |
35 ms |
8404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
51 ms |
11604 KB |
Output is correct |
3 |
Correct |
47 ms |
11604 KB |
Output is correct |
4 |
Correct |
36 ms |
11604 KB |
Output is correct |
5 |
Correct |
51 ms |
11508 KB |
Output is correct |
6 |
Correct |
37 ms |
11608 KB |
Output is correct |
7 |
Correct |
54 ms |
11592 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4560 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
51 ms |
11604 KB |
Output is correct |
3 |
Correct |
47 ms |
11604 KB |
Output is correct |
4 |
Correct |
36 ms |
11604 KB |
Output is correct |
5 |
Correct |
51 ms |
11508 KB |
Output is correct |
6 |
Correct |
37 ms |
11608 KB |
Output is correct |
7 |
Correct |
54 ms |
11592 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4560 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4560 KB |
Output is correct |
19 |
Correct |
1 ms |
4600 KB |
Output is correct |
20 |
Incorrect |
187 ms |
17636 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
51 ms |
11604 KB |
Output is correct |
3 |
Correct |
47 ms |
11604 KB |
Output is correct |
4 |
Correct |
36 ms |
11604 KB |
Output is correct |
5 |
Correct |
51 ms |
11508 KB |
Output is correct |
6 |
Correct |
37 ms |
11608 KB |
Output is correct |
7 |
Correct |
54 ms |
11592 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4560 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4560 KB |
Output is correct |
19 |
Correct |
1 ms |
4600 KB |
Output is correct |
20 |
Incorrect |
187 ms |
17636 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
51 ms |
11604 KB |
Output is correct |
3 |
Correct |
47 ms |
11604 KB |
Output is correct |
4 |
Correct |
36 ms |
11604 KB |
Output is correct |
5 |
Correct |
51 ms |
11508 KB |
Output is correct |
6 |
Correct |
37 ms |
11608 KB |
Output is correct |
7 |
Correct |
54 ms |
11592 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4560 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4560 KB |
Output is correct |
19 |
Correct |
1 ms |
4600 KB |
Output is correct |
20 |
Incorrect |
187 ms |
17636 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
283 ms |
25300 KB |
Output is correct |
6 |
Correct |
207 ms |
22096 KB |
Output is correct |
7 |
Correct |
315 ms |
24300 KB |
Output is correct |
8 |
Correct |
384 ms |
26396 KB |
Output is correct |
9 |
Correct |
406 ms |
29404 KB |
Output is correct |
10 |
Correct |
341 ms |
25072 KB |
Output is correct |
11 |
Correct |
393 ms |
26580 KB |
Output is correct |
12 |
Correct |
400 ms |
29500 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4704 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4440 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4556 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
2 ms |
4444 KB |
Output is correct |
42 |
Correct |
3 ms |
4560 KB |
Output is correct |
43 |
Correct |
4 ms |
4444 KB |
Output is correct |
44 |
Correct |
3 ms |
4444 KB |
Output is correct |
45 |
Correct |
4 ms |
4700 KB |
Output is correct |
46 |
Correct |
22 ms |
7224 KB |
Output is correct |
47 |
Correct |
27 ms |
7124 KB |
Output is correct |
48 |
Correct |
33 ms |
7260 KB |
Output is correct |
49 |
Correct |
26 ms |
7260 KB |
Output is correct |
50 |
Correct |
32 ms |
7496 KB |
Output is correct |
51 |
Correct |
192 ms |
22100 KB |
Output is correct |
52 |
Correct |
177 ms |
22100 KB |
Output is correct |
53 |
Correct |
404 ms |
32052 KB |
Output is correct |
54 |
Correct |
396 ms |
31920 KB |
Output is correct |
55 |
Correct |
1 ms |
4644 KB |
Output is correct |
56 |
Correct |
35 ms |
8404 KB |
Output is correct |
57 |
Correct |
1 ms |
4440 KB |
Output is correct |
58 |
Correct |
51 ms |
11604 KB |
Output is correct |
59 |
Correct |
47 ms |
11604 KB |
Output is correct |
60 |
Correct |
36 ms |
11604 KB |
Output is correct |
61 |
Correct |
51 ms |
11508 KB |
Output is correct |
62 |
Correct |
37 ms |
11608 KB |
Output is correct |
63 |
Correct |
54 ms |
11592 KB |
Output is correct |
64 |
Correct |
1 ms |
4444 KB |
Output is correct |
65 |
Correct |
1 ms |
4444 KB |
Output is correct |
66 |
Correct |
1 ms |
4444 KB |
Output is correct |
67 |
Correct |
1 ms |
4444 KB |
Output is correct |
68 |
Correct |
1 ms |
4560 KB |
Output is correct |
69 |
Correct |
1 ms |
4444 KB |
Output is correct |
70 |
Correct |
1 ms |
4444 KB |
Output is correct |
71 |
Correct |
1 ms |
4444 KB |
Output is correct |
72 |
Correct |
1 ms |
4444 KB |
Output is correct |
73 |
Correct |
1 ms |
4444 KB |
Output is correct |
74 |
Correct |
1 ms |
4560 KB |
Output is correct |
75 |
Correct |
1 ms |
4600 KB |
Output is correct |
76 |
Incorrect |
187 ms |
17636 KB |
Output isn't correct |
77 |
Halted |
0 ms |
0 KB |
- |