QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#629164#7932. AND-OR closureATM12345WA 1ms6168kbC++172.0kb2024-10-11 07:21:492024-10-11 07:21:50

Judging History

你现在查看的是最新测评结果

  • [2024-10-11 07:21:50]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6168kb
  • [2024-10-11 07:21:49]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define Ma 1000005 
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(x) x.begin(),x.end()
#define N 40
#define Ne 20
using namespace std;


ll n;
ll a[Ma];
ll col[N],cnt[N],add[N];
ll dp[1<<Ne];

ll lowbit(ll x)
{
	return x&(-x);
}

ll fa[N];

ll find(ll x)
{
	if (fa[x]==x)	return fa[x];
	return fa[x]=find(fa[x]);
}

void merage(ll x,ll y)
{
	x=find(x),y=find(y);
	if (x==y)
		return ;
	fa[y]=x;
	add[x]+=add[y];
	return;
}

bool cmp(ll x,ll y)
{
	return cnt[x]<cnt[y];
}

void sol()
{
	cin>>n;
	vector <ll> v;
	ll ma=0,mi=0;
	for (ll i=1;i<=n;i++){
		ll x;
		cin>>x;
		ma|=x,mi|=x;
		for (ll j=0;j<N;j++)
			for (ll k=0;k<N;k++)
				if ((x>>j&1)&&!(x>>k&1))
					col[j]|=(1ll<<k);
	}
	for (ll i=0;i<N;i++)
		fa[i]=i,add[i]=(1ll<<i);
	
	ll all=(1ll<<N)-1;
	vector <ll> g;
	for (ll i=0;i<N;i++)
	{
		col[i]=all-col[i];
		for (ll j=0;j<N;j++)
			if (col[i]>>j&1)
				cnt[i]++;
	//	printf("i=%lld cnt=%lld col=%lld\n",i,cnt[i],col[i]);
	}
	for (ll i=0;i<N;i++)
		for (ll j=0;j<N;j++)
			if ((col[i]>>j&1)&&(col[j]>>i&1))
				merage(i,j);
	for (ll i=0;i<N;i++)
		if (find(i)==i&&(ma>>i&1))
			g.pb(i);
			
	sort(all(g),cmp);
	ll siz=g.size(),L=siz/2,R=siz-L;
	for (ll i=0;i<(1ll<<L);i++)
	{
		ll x=0,y=0;
		for (ll j=0;j<L;j++)
			if (i>>j&1)
				x|=add[g[j]],y|=col[g[j]];
		if ((x&mi)!=mi)
			continue;
		if (x==y)
			dp[i]=1;
	}
	for (ll i=1;i<(1ll<<L);i<<=1)
		for (ll j=0;j<(1ll<<L);j+=2*i)
			for (ll k=0;k<i;k++)
				dp[j+k]+=dp[i+j+k];
	ll ans=0;
	for (ll i=0;i<(1ll<<R);i++)
	{
		ll x=0,y=0;
		for (ll j=0;j<R;j++)
			if (i>>j&1)
				x|=add[g[j+L]],y|=col[g[j+L]];
	//	printf("i=%lld x=%lld y=%lld\n",i,x,y);
		ll be=0;
		for (ll j=0;j<L;j++)
			if (y>>g[j]&1)
				be|=(1ll<<j),y-=add[g[j]];
	//	printf("i=%lld x=%lld y=%lld\n",i,x,y);
		if (x==y)
			ans+=dp[be];
	}
	printf("%lld\n",ans);
}



int main()
{
	IOS
	ll tt=1;
	//cin>>tt;
	while (tt--)
		sol();
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 6168kb

input:

4
0 1 3 5

output:

0

result:

wrong answer 1st numbers differ - expected: '5', found: '0'