| Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|---|
| 39004 | dtmm | 【S】T2 | C++ | 运行超时 | 0 | 1000 MS | 664 KB | 2129 | 2025-11-27 21:30:43 |
#include<bits/stdc++.h> #define int long long using namespace std; const int N=222,P=998244353,MX=15; int n,a[N],ans,A,B,fa[N],sz[N],t[N]; int qpow(int x,int y) { if(y==0)return 1; int z=qpow(x,y/2); if(y%2)return z*z%P*x%P; return z*z%P; } int check(int x,int y) { for(int i=0,j=1;i<=y;i++,j*=2) { if(i==y) { return x%2; } x/=2; } return 0; } void dfs(int x) { if(x>n) { if(A==B) { ans++; ans%=P; } return; } int y=A,z=B; A=A|a[x]; dfs(x+1); A=y; B=B|a[x]; dfs(x+1); B=z; } int findf(int x) { if(fa[x]==x)return x; fa[x]=findf(fa[x]); return fa[x]; } void hebing(int x,int y) { x=findf(x),y=findf(y); if(sz[x]>sz[y])swap(x,y); sz[y]+=sz[x]; fa[x]=y; } void panduan(int x) { int cnt=0; memset(t,0,sizeof(t)); for(int i=1;i<=n;i++) { int to=findf(i); if(!t[to]) { t[to]=1; cnt++; } } if(x%2) ans+=qpow(2,cnt); else ans-=qpow(2,cnt); } void dfss(int x,int y) { if(x>n) { panduan(y); return; } int rem[N]; dfss(x+1,y); stack<int>q; for(int j=1;j<=n;j++) { rem[j]=fa[j]; if(check(a[j],x)) { q.push(j); } } while(q.size()>1) { int x=q.top(); q.pop(); int y=q.top(); hebing(x,y); } dfss(x+1,y+1); for(int j=1;j<=n;j++) { fa[j]=rem[j]; } } signed main() { //freopen("partition.in","r",stdin); //freopen("partition.out","w",stdout); cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; fa[i]=i; sz[i]=1; } if(n<=0) { dfs(1); cout<<ans<<"\n"; //cout<<(double)clock()/CLOCKS_PER_SEC; return 0; } dfss(1,0); cout<<(qpow(2,n)-ans)%P<<"\n"; return 0; }