QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#350981#7932. AND-OR closuremc020207WA 0ms3780kbC++171.5kb2024-03-11 11:20:572024-03-11 11:20:58

Judging History

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

  • [2024-03-11 11:20:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3780kb
  • [2024-03-11 11:20:57]
  • 提交

answer

#include<bits/stdc++.h>
#define MAXN 1000010
#define INF 1000000010
#define INFLL (1LL*INF*INF)
#define MOD 1000000007
#define LL long long
#define LLL __int128_t
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rof(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const int B=39;
LL a[MAXN];
vector<LL> li;
int n;
LL solve(LL msk){
	if (li.empty()) return 1;
	sort(li.begin(),li.end());
	li.erase(unique(li.begin(),li.end()),li.end());
	// printf("li={");
	// for (LL x:li) printf("%lld ",x);
	// printf("}\n"); 
	int len=li.size();
	int mxp=0;
	For(i,1,len-1){
		if (__builtin_popcountll(li[i])>__builtin_popcountll(li[mxp])){
			assert((msk&li[i])==li[i]);
			mxp=i;
		}
	}
	if (__builtin_popcountll(li[mxp])==1) return 1LL<<len;
	vector<LL> li2=li;
	li.clear();
	LL msk2=msk-li[mxp];
	for (LL x:li2){
		if (msk2&x) li.push_back(msk2&x);
	}
	LL ans=solve(msk2);
	li=li2;
	LL old=li[mxp];
	li.erase(li.begin()+mxp);
	ans+=solve(msk);
	// printf("li={");
	// for (LL x:li) printf("%lld ",x);
	// printf("} ans=%lld\n",ans);
	return ans;
}
void Main(){
	li.clear();
	cin>>n;
	For(i,1,n) cin>>a[i];
	For(i,0,B){
		LL t=-1;
		For(j,1,n){
			if (a[j]&(1LL<<i)) t=t==-1?a[j]:t&a[j];
		}
		if (t!=-1) li.push_back(t);
	}
	LL andsum=a[1];
	For(i,2,n) andsum&=a[i];
	cout<<solve((1LL<<40)-1)-(andsum!=0)<<"\n";
}	
int main(){
	std::ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int T=1;cin>>T;
	while (T--) Main();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3780kb

input:

4
0 1 3 5

output:

1
1
2
2

result:

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