QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#759196 | #7932. AND-OR closure | ucup-team3924 | WA | 104ms | 5320kb | C++20 | 3.7kb | 2024-11-17 23:02:05 | 2024-11-17 23:02:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int lim = 40;
int graph[lim][lim];
bool vis[lim];
long long dfs(int node) {
vis[node] = true;
long long mask = 0LL;
mask |= (1LL << node);
for (int i = 0; i < lim; i++) {
if (graph[node][i] && !vis[i]) {
mask |= dfs(i);
}
}
return mask;
}
long long reach_mask[lim];
bool newgraph[lim][lim];
std::vector<bool> get_indep_sets(std::vector<int> nodes) {
int n = nodes.size();
std::vector<bool> isindep(1 << n);
isindep[0] = true;
for (int mask = 1; mask < (1 << n); mask++) {
int last_bit = 0;
while ((mask & (1 << last_bit)) == 0) last_bit++;
isindep[mask] = isindep[mask ^ (1 << last_bit)];
for (int i = last_bit + 1; i < n; i++) {
if ((1 << i) & mask) {
if (newgraph[nodes[last_bit]][nodes[i]])
isindep[mask] = false;
}
}
}
return isindep;
}
long long count_indep_sets(int n) {
std::vector<int> index(n);
std::vector<int> half1, half2;
for (int i = 0; i < n; i++) {
if (i < n / 2) {
index[i] = half1.size();
half1.push_back(i);
} else {
index[i] = half2.size();
half2.push_back(i);
}
}
auto indep_a = get_indep_sets(half1);
auto indep_b = get_indep_sets(half2);
std::vector<int> count_indep(1 << half2.size());
for (int i = 0; i < (1 << half2.size()); i++)
count_indep[i] += indep_b[i];
for (int b = 0; b < half2.size(); b++)
for (int i = (1 << half2.size()) - 1; i >= 0; i--)
if ((i & (1 << b))) {
count_indep[i] += count_indep[i ^ (1 << b)];
}
long long res = 0LL;
std::vector<int> cross_vec(half1.size());
for (int i = 0; i < half1.size(); i++) {
for (auto j: half2)
if (newgraph[i][j])
cross_vec[i] |= (1 << index[j]);
}
for (int i = 0; i < (1 << half1.size()); i++) {
if (indep_a[i]) {
int cross = 0;
for (int j = 0; j < half1.size(); j++)
if ((1 << j) & i)
cross |= cross_vec[j];
res += count_indep[(1 << half2.size()) - 1 - cross];
}
}
return res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<long long>a(n);
long long all = 0;
for(auto &x: a)cin >> x;
for(auto x : a)all |= x;
for(int bit = 0; bit < lim; bit++){
long long x = all;
for(auto y : a){
if((1LL<<bit)&y)x&=y;
}
if(((1LL<<bit)&x) > 0){
for(int bit2 = 0; bit2 < lim; bit2++){
if(bit==bit2)continue;
if((1LL<<bit2)&x){
graph[bit][bit2] = 1;
}
}
} else {
graph[bit][bit] = 1;
}
}
all = (1LL << 40) - 1;
for (auto x: a) all &= x;
for (int i = 0; i < lim; i++) {
if (!graph[i][i]) {
for (int j = 0; j < lim; j++)
vis[j] = false;
reach_mask[i] = dfs(i);
}
}
std::map<long long, int> recolor;
int last = 0;
for (int i = 0; i < lim; i++) {
if (!graph[i][i]) {
recolor[reach_mask[i]] = last++;
}
}
for (int i = 0; i < lim; i++)
for (int j = 0; j < lim; j++) {
if (!graph[i][i] && !graph[j][j] && graph[i][j]) {
newgraph[recolor[reach_mask[i]]][recolor[reach_mask[j]]] =
newgraph[recolor[reach_mask[j]]][recolor[reach_mask[i]]] = 1;
}
}
std::cout << count_indep_sets(last) - (all != 0);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 104ms
memory: 5320kb
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:
3556769791
result:
wrong answer 1st numbers differ - expected: '52', found: '3556769791'