QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#384461#7932. AND-OR closureGiga_Cronos#WA 3ms11452kbC++233.6kb2024-04-10 00:11:452024-04-10 00:11:46

Judging History

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

  • [2024-04-10 00:11:46]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:11452kb
  • [2024-04-10 00:11:45]
  • 提交

answer

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops",
// "omit-frame-pointer", "inline") #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native")
// #pragma GCC option("arch=native", "no-zero-upper") // Enable AVX

/// UH Top
#include <bits/stdc++.h>
#define db(x)   cerr << #x << ':' << (x) << '\n';
#define all(v)  (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
// #define int ll
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// typedef __int128_t int128;
typedef pair<ll, ll> pii;
typedef pair<ld, ll> pdi;
typedef pair<ld, ld> pdd;
typedef pair<ld, pdd> pdp;
typedef pair<string, ll> psi;
typedef pair<ll, string> pls;
typedef pair<string, string> pss;
typedef pair<ll, pii> pip;
typedef pair<pii, pii> ppp;
typedef complex<ld> point;
typedef vector<point> polygon;
typedef vector<ll> vi;
typedef pair<point, int> ppi;
#define prec(n)                                                                \
	cout.precision(n);                                                         \
	cout << fixed
const ll mod = (1e9 + 7);
const ld eps = (1e-9);
const ll oo = (ll)(1e18 + 5);
#define pi   acos(-1)
#define MAXN (ll)(4e1 + 5)

vector<int> g[MAXN];
ll mask[MAXN];
int trans[MAXN];
ll dag[MAXN];
int lg[((ll)(2e6 + 5))];

void dfs(int u, int l) {
	mask[l] |= (1ll << u);
	for (auto v : g[u])
		if (!(mask[l] & (1ll << v)))
			dfs(v, l);
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	lg[0] = -1;
	for (int i = 1; i < 2e6; i++)
		lg[i] = lg[i - 1] + !(i & (i - 1));

	int n;
	cin >> n;
	ll or_sum = 0;
	vector<int> a(n);
	int hay0 = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		or_sum |= a[i];
		hay0 = (hay0 || (a[i] == 0));
	}
	// cout << hay0 << "\n";
	for (int i = 0; i < 40; i++)
		if (or_sum & (1ll << i)) {
			ll val = or_sum;
			for (int j = 0; j < n; j++)
				if (a[j] & (1ll << i))
					val &= a[j];
			// cout << i << ' ' << val << "\n";
			for (int j = 0; j < 40; j++)
				if (j != i && (val & (1ll << j)))
					g[i].push_back(j);
		}

	for (int i = 0; i < 40; i++)
		if (or_sum & (1ll << i))
			dfs(i, i);

	int cont = 1;
	for (int i = 0; i < 40; i++)
		if (!trans[i] && (or_sum & (1ll << i))) {
			for (int j = 0; j < 40; j++)
				if ((mask[i] & (1ll << j)) && (mask[j] & (1ll << i)))
					trans[j] = cont;
			cont++;
		}

	for (int i = 0; i < 40; i++)
		for (int j = 0; j < 40; j++)
			if ((mask[i] & (1ll << j)) && trans[i] != trans[j]) {
				dag[trans[i] - 1] |= (1ll << (trans[j] - 1));
				dag[trans[j] - 1] |= (1ll << (trans[i] - 1));
			}

	cont--;
	// cout << cont << "\n";
	int lim = 20;
	if (cont <= lim) {
		int ans = 0;
		for (int i = !hay0; i < (1 << cont); i++) {
			ll msk = 0;
			for (int j = 0; j < cont; j++)
				if (i & (1 << j))
					msk |= dag[j];
			// cout << i << ' ' << msk << "\n";
			if (!(msk & i))
				ans++;
		}
		cout << ans << "\n";
	} else {
		vector<int> pre(1 << lim, 1);
		for (int i = 1; i < (1 << lim); i++) {
			int last = lg[i & -i];
			ll op = (((1ll << cont) - 1) ^ dag[last]) ^ (1 << last);
			pre[i] = pre[i ^ (1 << last)] + pre[i & op];
		}

		ll ans = 0;
		for (int i = 0; i < (1 << (cont - lim)); i++) {
			ll msk = 0;
			for (int j = 0; j < cont - lim; j++)
				if (i & (1 << j))
					msk |= dag[j + lim];
			if (msk & ((1ll * i) << lim))
				continue;
			ll op = ((1ll << cont) - 1) ^ msk;
			ans += pre[op & ((1ll << lim) - 1)];
		}
		cout << ans - 1 + hay0 << "\n";
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 11316kb

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

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:

2

result:

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