#include<stdio.h> #include<math.h> #include<cstdlib> #define il inline usingnamespace std; constint N=205;
int n,m,sx,sy; int ok[N][N],p[N*N],q[N*N];
il voiddfs(int x,int y,int c) { int i; if (c>n*m){for (i=1; i<=n*m; i++) printf("%d %d\n",p[i],q[i]);exit(0);} for (i=1; i<=n; i++) if (!ok[i][y]) ok[i][y]=1,p[c]=i,q[c]=y,dfs(i,y,c+1),ok[i][y]=0; for (i=1; i<=m; i++) if (!ok[x][i]) ok[x][i]=1,p[c]=x,q[c]=i,dfs(x,i,c+1),ok[x][i]=0; }
intmain() { scanf("%d%d",&n,&m); int i,j,k,o1,o2; for (i=1; i<=n; i++) scanf("%d",a+i),t=max(t,a[i]); for (j=1; j<=m; j++) { scanf("%d",&k),t=max(t,k); for (i=1; i<=n; i++) b[i][j]=a[i]&k; } for (k=9; ~k; k--) if ((1<<k)<=t) { for (i=o1=1; i<=n; i++) { for (j=o2=1; j<=m; j++) if (b[i][j]>=0&&!(b[i][j]>>k&1)){o2--;break;} if (o2){o1--;break;} } if (!o1) ans+=1<<k; else{for (i=1; i<=n; i++) for (j=1; j<=m; j++) if (b[i][j]>>k&1) b[i][j]=-1;} } printf("%d",ans); return0; }
#include<stdio.h> #include<algorithm> #include<vector> #define il inline #define ll long long usingnamespace std; constint N=2e5+5; const ll P1=998244353,P2=1e9+7;
int n,m,k; vector<pair<int,int> > e[N]; vector<int> v[10]; ll ans,s1,s2,t1[N],t2[N],p1[10][10],p2[10][10];
il voiddfs(int c,ll p,ll q) { if (c>k){ans+=(p==s1&&q==s2);return;} int i; for (i=0; i<c; i++) dfs(c+1,(p+p1[c][i])%P1,(q+p2[c][i])%P2); }
intmain() { scanf("%d%d%d",&n,&m,&k); int i,j,w;t1[0]=t2[0]=1; for (i=1; i<=n; i++) s1=(s1+(t1[i]=t1[i-1]*2347623ll%P1))%P1,s2=(s2+(t2[i]=t2[i-1]*19260817ll%P2))%P2; while (m--) scanf("%d%d%d",&i,&j,&w),e[i].push_back(make_pair(w,j)); for (i=1; i<=n; i++) sort(e[i].begin(),e[i].end()),v[e[i].size()].push_back(i); for (i=1; i<=k; i++) for (j=0; j<i; j++) for (auto w:v[i]) p1[i][j]=(p1[i][j]+t1[e[w][j].second])%P1,p2[i][j]=(p2[i][j]+t2[e[w][j].second])%P2; dfs(1,0,0),printf("%lld",ans); return0; }
#include<stdio.h> #include<string.h> #include<algorithm> #define il inline usingnamespace std; constint N=5e5+5;
int n,ans,x[N],y[N],X1,X2,Y1,Y2,Z1,Z2; char s[N];
il voidwork(int l) { int i; X1=Y1=Z1=-1e9,X2=Y2=Z2=1e9; for (i=1; i<=n; i++) X1=max(X1,x[i]-l),X2=min(X2,x[i]+l), Y1=max(Y1,y[i]-l),Y2=min(Y2,y[i]+l), Z1=max(Z1,x[i]-y[i]-l),Z2=min(Z2,x[i]-y[i]+l); }
il intcheck(int l) { work(l); if (X1>X2||Y1>Y2||Z1>Z2||X1-Y2>Z2||X2-Y1<Z1) return0; return1; }
intmain() { scanf("%d",&n); int i,j,l,r,mid; for (i=1; i<=n; i++) { scanf("%s",s+1),l=strlen(s+1); for (j=1; j<=l; j++) if (s[j]=='B') x[i]++; else y[i]++; } for (l=0,r=N+N; l<=r; ) { mid=l+r>>1; if (check(mid)) ans=mid,r=mid-1; else l=mid+1; } printf("%d\n",ans),work(ans),X1=max(X1,0),Y1=max(Y1,0); l=min(X2,Y2+Z2),r=min(l-Z1,Y2); while (l--) putchar('B'); while (r--) putchar('N'); return0; }