Submission #979116

#TimeUsernameProblemLanguageResultExecution timeMemory
979116sleepntsheepCouncil (JOI23_council)C11
6 / 100
63 ms18524 KiB
#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; } int super(int x) { return x | x + 1; } int sub(int x) { return x & x - 1; } 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,-1,sizeof f); memset(g,-1,sizeof g); 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[i][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 (stderr)

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 'super':
council.c:10:33: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
   10 | int super(int x) { return x | x + 1; }
      |                               ~~^~~
council.c: In function 'sub':
council.c:11:31: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   11 | int sub(int x) { return x & x - 1; }
      |                             ~~^~~
council.c: In function 'main':
council.c:33:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d%d",&n,&m);
      |     ^~~~~~~~~~~~~~~~~~~
council.c:37:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |             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...