QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378136 | #7932. AND-OR closure | tylerm390# | WA | 12ms | 19532kb | C++20 | 2.0kb | 2024-04-06 06:47:48 | 2024-04-06 06:47:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
using pii = pair<int, int>;
using vvi = vector<vi>;
using vll = vector<ll>;
#define rep(i, a, b) for(int i = a; i < (b); i++)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define bitat(x, i) (((x)>>(i))&(1))
void solve() {
int n;
cin >> n;
vector<ll> arr(40, 0);
ll tot = (1ll<<40)-1;
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
tot &= x;
for (int j = 0; j < 40; j++) {
if (bitat(x, j)) arr[j] = (arr[j] == 0 ? x : arr[j]&x);
}
}
for (int i = 0; i < 40; i++) {
for (int j = i+1; j < 40; j++) {
if (bitat(arr[i], j) && bitat(arr[j], i)) arr[j] = 0;
}
}
for (int i = 0; i < 40; i++) {
for (int j = 0; j < 40; j++) if (bitat(arr[i], j)) arr[j] |= (1ll<<i);
}
for (int i = 0; i < 40; i++) {
if (arr[i]) arr[i] -= (1ll<<i);
else arr[i] = -1;
}
// for (int i = 0; i < 40; i++) cout << (1ll<<i) << ": " << arr[i] << endl;
vll ways(1<<20);
ways[0] = 1;
for (int i = 1; i < (1<<20); i++) {
int low = __builtin_ctz(i);
ways[i] = ways[i&(i-1)]*((arr[low]&i) == 0);
}
for (int bit = 1; bit < (1<<20); bit *= 2) {
for (int i = 0; i < (1<<20); i++) {
if ((i^bit) < i) ways[i] += ways[i^bit];
}
}
ll res = ways[(1<<20)-1];
vll ways2(1<<20);
cout << res << "\n";
for (ll i = 1; i < (1<<20); i++) {
int low = __builtin_ctz(i);
ways2[i] = ways2[i&(i-1)] | arr[low+20];
if ((ways2[i]&(i<<20)) == 0) {
// cout << i << " " << ways2[i] << " " << (1ll<<20)-1-(ways2[i]&((1<<20)-1)) << endl;
res += ways[(1ll<<20)-1-(ways2[i]&((1<<20)-1))];
}
}
cout << res - (tot != 0) << "\n";
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 12ms
memory: 19532kb
input:
4 0 1 3 5
output:
5 5
result:
wrong answer Output contains longer sequence [length = 2], but answer contains 1 elements