QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#502735 | #7932. AND-OR closure | ucup-team1766 | WA | 1ms | 3872kb | C++17 | 3.2kb | 2024-08-03 12:44:04 | 2024-08-03 12:44:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int BITS = 40;
const int SPLIT = 20;
bitset<MAXN> bits[BITS];
bitset<MAXN> zero;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int val;
cin >> val;
for (int j = 0; j < BITS; j++) {
bits[j][i] = val & 1;
val >>= 1;
}
}
bitset<MAXN> one;
for (int i = 0; i < n; i++) {
one[i] = 1;
}
vector<bitset<MAXN>> unique;
for (int i = 0; i < BITS; i++) {
bool cur_new = true;
for (int j = 0; j < i; j++) {
if (bits[j] == bits[i]) {
cur_new = false;
break;
}
}
if (bits[i] != zero && bits[i] != one && cur_new) {
unique.push_back(bits[i]);
}
}
int m = unique.size();
if (m == 0) {
cout << ";fslkjsad\n";
return 0;
}
vector<uint64_t> DAG(m);
for (int i = 0; i < m; i++) {
for (int j = i + 1; j < m; j++) {
bitset<MAXN> or_bs = (unique[i] | unique[j]);
if (or_bs == unique[i] || or_bs == unique[j]) {
DAG[i] = DAG[i] | (1 << j);
DAG[j] = DAG[j] | (1 << i);
}
}
}
int half = min(SPLIT, m);
// dp[i][mask] = # of subsets of mask differing only in the first i bits that are antichains
vector<vector<int>> sos_dp(half + 1, vector<int>(1 << half));
for (uint64_t mask = 0; mask < (1 << half); mask++) {
bool antichain = true;
for (int j = 0; j < half; j++) {
if (mask & (1 << j)) {
if ((DAG[j] & mask) != 0) {
antichain = false;
break;
}
}
}
if (antichain) {
sos_dp[0][mask] = 1;
}
}
for (int i = 1; i <= half; i++) {
for (uint64_t mask = 0; mask < (1 << half); mask++) {
sos_dp[i][mask] = sos_dp[i - 1][mask];
if (mask & (1 << (i - 1))) {
sos_dp[i][mask] += sos_dp[i - 1][mask ^ (1 << (i - 1))];
}
}
}
if (m > SPLIT) {
int ohalf = m - half;
long long res = 0;
for (uint64_t mask = 0; mask < (1 << ohalf); mask++) {
uint64_t real_mask = mask << half;
bool antichain = true;
for (int j = half; j < m; j++) {
if (real_mask & (1 << j)) {
if ((DAG[j] & real_mask) != 0) {
antichain = false;
break;
}
}
}
if (antichain) {
uint64_t left_mask = 0;
for (int j = 0; j < half; j++) {
if ((DAG[j] & real_mask) == 0) {
left_mask = left_mask | (1 << j);
}
}
res += sos_dp[half][left_mask];
}
}
cout << res << "\n";
} else {
cout << sos_dp[half][(1 << half) - 1] << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3864kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3796kb
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:
;fslkjsad
result:
wrong output format Expected integer, but ";fslkjsad" found