QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#629150#7932. AND-OR closureATM12345WA 154ms14012kbC++171.5kb2024-10-11 06:39:342024-10-11 06:39:35

Judging History

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

  • [2024-10-11 06:39:35]
  • 评测
  • 测评结果:WA
  • 用时:154ms
  • 内存:14012kb
  • [2024-10-11 06:39:34]
  • 提交

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];
ll dp[1<<Ne];

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


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

void sol()
{
	cin>>n;
	vector <ll> v;

	for (ll i=1;i<=n;i++){
		ll x;
		cin>>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);
	}
	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]);
		g.pb(i);
	}
	sort(all(g),cmp);
	for (ll i=0;i<(1<<Ne);i++)
	{
		ll x=0,y=0;
		for (ll j=0;j<Ne;j++)
			if (i>>j&1)
				x|=(1ll<<g[j]),y|=col[g[j]];
		if (x==y)
			dp[i]=1;
	}
	for (ll i=1;i<(1<<Ne);i<<=1)
		for (ll j=0;j<(1<<Ne);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<(1<<Ne);i++)
	{
		ll x=0,y=0;
		for (ll j=0;j<Ne;j++)
			if (i>>j&1)
				x|=(1ll<<g[j+Ne]),y|=col[g[j+Ne]];
		ll be=0;
		for (ll j=0;j<Ne;j++)
			if (y>>g[j]&1)
				be|=(1ll<<j),y-=(1ll<<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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 150ms
memory: 13048kb

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 153ms
memory: 13164kb

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Wrong Answer
time: 154ms
memory: 14012kb

input:

49
1097363587067 1096810445814 275012137504 1096739142630 1096809921522 1087071335264 829364908576 949625500192 1087142638448 1096200190829 1097292808175 1095750860656 1087144145776 1097346808827 1095734082416 1096755396578 829230678048 1095663303524 1087072842592 1096216444777 949623992864 10962714...

output:

54

result:

wrong answer 1st numbers differ - expected: '52', found: '54'