#include<stdio.h>
#include<string.h>
#define N 300000
#define M 20
int a[N], n, m, cc[M], f[1<<M][2], g[1<<M][2];
int count(int x) { return x ? 1 + count(x&x-1) : 0; }
void put(int i, int v)
{
if (v>f[i][0])
f[i][1]=f[i][0],f[i][0]=v;
else if(v>f[i][1])
f[i][1]=v;
}
void put_(int i, int v)
{
if (v > f[i][0])
f[i][1]=f[i][0],f[i][0]=v;
else if(v>f[i][1])
f[i][1]=v;
}
int main()
{
memset(f,0,sizeof f);
scanf("%d%d",&n,&m);
for(int i=0;i<n;++i)
{
for(int x,j=0;j<m;++j)
scanf("%d",&x),a[i]|=x<<j, cc[j]+=x;
int b=((1<<m)-1)&~a[i];
put(b, count(b));
}
/* need to find max count(b[i] & S)
* SOS dp :question:
*
*/
for(int i=0;i<m;++i)
for(int j=0;j<(1<<m);++j)
if(1==((j>>i)&1))
put(j^(1<<i), f[j][1]-1), put(j^(1<<i), f[j][0]-1);
for(int i=0;i<m;++i)
for(int j=0;j<(1<<m);++j)
if(0==(j&(1<<i)))
put_(j^(1<<i), f[j][1]), put_(j^(1<<i), f[j][0]);
for(int i=0;i<n;++i)
{
int S=0,ans=0;
for(int j=0;j<m;++j)
{
int c=cc[j]-((a[i]>>j)&1);
if (c>n/2)
++ans;
else if(c==n/2)
S|=1<<j;
}
int b=((1<<m)-1)&~a[i];
if (count(S&b) == f[S][0])
ans += f[S][1];
else
ans += f[S][0];
printf("%d\n", ans);
}
}
Compilation message
council.c: In function 'count':
council.c:9:44: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
9 | int count(int x) { return x ? 1 + count(x&x-1) : 0; }
| ~^~
council.c: In function 'main':
council.c:30:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%d%d",&n,&m);
| ^~~~~~~~~~~~~~~~~~~
council.c:34:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | scanf("%d",&x),a[i]|=x<<j, cc[j]+=x;
| ^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Incorrect |
2 ms |
10588 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Incorrect |
2 ms |
10588 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
61 ms |
11332 KB |
Output is correct |
3 |
Correct |
68 ms |
11140 KB |
Output is correct |
4 |
Correct |
43 ms |
11092 KB |
Output is correct |
5 |
Correct |
56 ms |
11088 KB |
Output is correct |
6 |
Correct |
46 ms |
11428 KB |
Output is correct |
7 |
Correct |
70 ms |
11052 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
1 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10588 KB |
Output is correct |
11 |
Correct |
1 ms |
10588 KB |
Output is correct |
12 |
Correct |
1 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
1 ms |
10692 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
61 ms |
11332 KB |
Output is correct |
3 |
Correct |
68 ms |
11140 KB |
Output is correct |
4 |
Correct |
43 ms |
11092 KB |
Output is correct |
5 |
Correct |
56 ms |
11088 KB |
Output is correct |
6 |
Correct |
46 ms |
11428 KB |
Output is correct |
7 |
Correct |
70 ms |
11052 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
1 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10588 KB |
Output is correct |
11 |
Correct |
1 ms |
10588 KB |
Output is correct |
12 |
Correct |
1 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
1 ms |
10692 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
1 ms |
10588 KB |
Output is correct |
20 |
Incorrect |
217 ms |
16976 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
61 ms |
11332 KB |
Output is correct |
3 |
Correct |
68 ms |
11140 KB |
Output is correct |
4 |
Correct |
43 ms |
11092 KB |
Output is correct |
5 |
Correct |
56 ms |
11088 KB |
Output is correct |
6 |
Correct |
46 ms |
11428 KB |
Output is correct |
7 |
Correct |
70 ms |
11052 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
1 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10588 KB |
Output is correct |
11 |
Correct |
1 ms |
10588 KB |
Output is correct |
12 |
Correct |
1 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
1 ms |
10692 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
1 ms |
10588 KB |
Output is correct |
20 |
Incorrect |
217 ms |
16976 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
61 ms |
11332 KB |
Output is correct |
3 |
Correct |
68 ms |
11140 KB |
Output is correct |
4 |
Correct |
43 ms |
11092 KB |
Output is correct |
5 |
Correct |
56 ms |
11088 KB |
Output is correct |
6 |
Correct |
46 ms |
11428 KB |
Output is correct |
7 |
Correct |
70 ms |
11052 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
1 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
10588 KB |
Output is correct |
11 |
Correct |
1 ms |
10588 KB |
Output is correct |
12 |
Correct |
1 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
1 ms |
10692 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
1 ms |
10588 KB |
Output is correct |
20 |
Incorrect |
217 ms |
16976 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Incorrect |
2 ms |
10588 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |