QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#304882 | #7932. AND-OR closure | ucup-team859 | RE | 1ms | 9736kb | C++17 | 3.3kb | 2024-01-14 04:58:31 | 2024-01-14 04:58:32 |
Judging History
answer
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
const int maxN = 200000, k = 40;
int n;
bitset <maxN> on[k];
bool useless[k], edge[k][k];
bool ok1[(1 << 20)], ok2[(1 << 20)];
long long sos[(1 << 20)], ans;
int ban[(1 << 20)];
vector <int> bits;
int main() {
#ifdef LOCAL
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#endif // LOCAL
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
for (int bit = 0; bit < k; bit++) {
if (x & (1LL << bit)) {
on[bit][x] = 1;
}
}
}
for (int bit1 = 0; bit1 < k; bit1++) {
int sz = on[bit1].count();
if (sz == 0 || sz == n) {
useless[bit1] = 1;
}
if (useless[bit1]) {
continue;
}
for (int bit2 = bit1 + 1; bit2 < k; bit2++) {
if (on[bit1] == on[bit2]) {
useless[bit2] = 1;
}
}
}
for (int bit = 0; bit < k; bit++) {
if (!useless[bit]) {
on[bits.size()] = on[bit];
bits.push_back(bit);
}
}
n = bits.size();
for (int bit1 = 0; bit1 < n; bit1++) {
for (int bit2 = bit1 + 1; bit2 < n; bit2++) {
bitset <maxN> aux = (on[bit1] & on[bit2]);
if (aux == on[bit1] || aux == on[bit2]) {
edge[bit1][bit2] = 1;
edge[bit2][bit1] = 1;
}
}
}
int n1 = n/2, n2 = n - n/2;
ok1[0] = 1;
ok2[0] = 1;
sos[0] = 1;
for (int mask = 1; mask < (1 << n1) || mask < (1 << n2); mask++) {
int bit = 0;
while ((mask & (1 << bit)) == 0) {
bit++;
}
if ((mask < (1 << n1)) && ok1[mask ^ (1 << bit)]) {
ok1[mask] = 1;
for (int bit2 = bit + 1; bit2 < n1; bit2++) {
if ((mask & (1 << bit2)) && edge[bit][bit2]) {
ok1[mask] = 0;
break;
}
}
}
if ((mask < (1 << n2)) && ok2[mask ^ (1 << bit)]) {
ok2[mask] = 1;
for (int bit2 = bit + 1; bit2 < n2; bit2++) {
if ((mask & (1 << bit2)) && edge[n1 + bit][n1 + bit2]) {
ok2[mask] = 0;
break;
}
}
sos[mask] = ok2[mask];
}
}
for (int bit = 0; bit < n2; bit++) {
for (int mask = 1; mask < (1 << n2); mask++) {
if (mask & (1 << bit)) {
sos[mask] += sos[mask ^ (1 << bit)];
}
}
}
for (int mask = 1; mask < (1 << n1); mask++) {
int bit = 0;
while ((mask & (1 << bit)) == 0) {
bit++;
}
ban[mask] = ban[mask ^ (1 << bit)];
for (int bit2 = 0; bit2 < n2; bit2++) {
if (edge[bit][n1 + bit2]) {
ban[mask] |= (1 << bit2);
}
}
}
int full = (1 << n2) - 1;
for (int mask = 0; mask < (1 << n1); mask++) {
if (!ok1[mask]) {
continue;
}
ans += sos[full ^ ban[mask]];
}
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7800kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 1ms
memory: 9736kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Runtime Error
input:
49 1097363587067 1096810445814 275012137504 1096739142630 1096809921522 1087071335264 829364908576 949625500192 1087142638448 1096200190829 1097292808175 1095750860656 1087144145776 1097346808827 1095734082416 1096755396578 829230678048 1095663303524 1087072842592 1096216444777 949623992864 10962714...