QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#316851#7932. AND-OR closurenvujicaWA 0ms3652kbC++141.5kb2024-01-28 04:47:292024-01-28 04:47:29

Judging History

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

  • [2024-01-28 04:47:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3652kb
  • [2024-01-28 04:47:29]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long
#define fi first
#define se second

using namespace std;

const int maxn = 2e5 + 10, LOG = 40;

int n, m;
ll ost;
ll a[maxn];
vector <ll> v;

void ispis(ll x){
	for(int i = 0; i < LOG; i++){
		if(x & (1LL << i)) cout << 1;
		else cout << 0;
	}
	cout << endl;
}

//bool cmp(ll x, ll y){
//	return __builtin_popcountll(x) < __builtin_popcountll(y);
//}

ll rek(){
	if(v.empty()) return 1;
	
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
//	sort(v.begin(), v.end(), cmp)

	int naj = 0;
	
	for(int i = 0; i < v.size(); i++){
		if(__builtin_popcountll(v[i]) > __builtin_popcountll(v[naj])) naj = i;
	}
	
//	for(int i = 0; i < v.size(); i++){
//		ispis(v[i]);
//	}
//	
//	cout << endl;
	
	ll sol = 0;
	
	vector <ll> v2 = v;
	v.clear();
	
	ost ^= v[naj];
	
	for(int i = 0; i < v2.size(); i++){
		if(v2[i] & ost) v.push_back(v2[i] & ost);
	}
	
	sol += rek();
	v = v2;
	
	ost ^= v[naj];
	
	v.pop_back();
	sol += rek();
	v = v2;
	
	return sol;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	
	bool nula = 0;
	
	for(int i = 0; i < n; i++){
		cin >> a[i];
	
		if(!a[i]) nula = 1;
	}
	
	vector <ll> v2;
	
	for(int i = 0; i < LOG; i++){
		ll x = (1LL << 42) - 1;
		
		for(int j = 0; j < n; j++){
			if(a[j] & (1LL << i)) x &= a[j];
		}
		
		if(x != (1LL << 42) - 1){
			v.push_back(x);
			ost |= (1LL << i);
		}
	}
	
//	ispis(ost);
	
	cout << rek() - !nula;
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

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:

52

result:

ok 1 number(s): "52"

Test #4:

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

input:

40
32 830045728951 278250692646 1021660937663 881584025918 275993636902 275953000615 327534555567 329833558447 278293950631 327534558639 893011227647 327533244718 1021660934591 1021661000703 893011161535 1030787822591 832344731831 275994947751 1073741862 329832247598 278292639782 1030787825663 10307...

output:

37

result:

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