QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#673773#7932. AND-OR closurerotcar07WA 0ms3644kbC++23900b2024-10-25 10:03:402024-10-25 10:03:42

Judging History

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

  • [2024-10-25 10:03:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-10-25 10:03:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;ll zhuzhu[40],b[40],msk[40];
int dp[1<<20];
int main(){
	cin>>n;ll ans=(1ll<<40)-1;
	for(int i=1;i<=n;i++){
		ll x;cin>>x;
		for(int j=0;j<40;j++)if(x>>j&1){
			if(!zhuzhu[j]) zhuzhu[j]=x;
			else zhuzhu[j]&=x;
		}
		ans&=x;
	}n=0;ans=0;
	for(int i=0;i<40;i++)if(zhuzhu[i]) b[n++]=zhuzhu[i];
	sort(b,b+n);n=unique(b,b+n)-b;
	int nn=n/2;
	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++) if(i!=j&&(b[i]&b[j])==min(b[i],b[j])) msk[i]|=1<<j;
	for(int i=0;i<1<<nn;i++){
		int sb=0;
		for(int j=0;j<nn;j++)if(i>>j&1) sb|=msk[j];
		if(sb&i);
		else dp[i]=1;
	}
	for(int j=0;j<nn;j++)
	for(int i=0;i<1<<nn;i++)if(i>>j&1) dp[i]+=dp[i^(1<<j)];
	for(int i=0;i<1<<n-nn;i++){
		int sb=0;
		for(int j=nn;j<n;j++)if(i>>j-nn&1) sb|=msk[j];
		if((sb>>nn)&i);
		else ans+=dp[(~sb)&(1<<nn)-1];
	}
	cout<<ans<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3644kb

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:

53

result:

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