Submission #979135

#TimeUsernameProblemLanguageResultExecution timeMemory
979135sleepntsheepCouncil (JOI23_council)C11
100 / 100
1619 ms23696 KiB
#include<stdio.h> #include<assert.h> #include<string.h> #define N 300000 #define M 20 int a[N], b[N], n, m, cc[M], f[1<<M][2]; int count(int x) { return x ? 1 + count(x&x-1) : 0; } int gt(int i,int j,int s){if(i==-1)return 0;if(j==-1)return 1;return count(b[i]&s)>count(b[j]&s);} void put_(int i, int v) { if (gt(v, f[i][0], i)) f[i][1]=f[i][0],f[i][0]=v; else if (v != f[i][0] && gt(v, f[i][1], i)) f[i][1]=v; } int main() { memset(f,-1,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; b[i]=((1<<m)-1)&~a[i]; put_(b[i], i); } /* 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)) { int jj=j^(1<<i); put_(jj, f[j][1]); put_(jj, f[j][0]); } for(int i=0;i<m;++i) for(int j=0;j<(1<<m);++j) if(0==((j>>i)&1)) { int jj=j^(1<<i); put_(jj, f[j][1]); put_(jj, 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; } if (i == f[S][0]) ans += count(b[f[S][1]]&S); else ans += count(b[f[S][0]]&S); printf("%d\n", ans); } }

Compilation message (stderr)

council.c: In function 'count':
council.c:10:44: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   10 | int count(int x) { return x ? 1 + count(x&x-1) : 0; }
      |                                           ~^~
council.c: In function 'main':
council.c:25:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d%d",&n,&m);
      |     ^~~~~~~~~~~~~~~~~~~
council.c:29:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |             scanf("%d",&x),a[i]|=x<<j, cc[j]+=x;
      |             ^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...