QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#332089 | #7932. AND-OR closure | UNos_maricones# | WA | 29ms | 9320kb | C++14 | 2.9kb | 2024-02-19 08:32:43 | 2024-02-19 08:32:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef pair <int,int> pii;
const int N = 200'005;
const int LOGM = 40;
const ll INF = (1LL<<41)-1LL;
const int TOT_MASK = (1<<20)-1;
ll arr[N];
int n;
ll mask[LOGM];
bool banned[LOGM];
vector <int> g[LOGM];
void createGraph () {
for ( int i = 0; i < LOGM; ++i )
mask[i] = INF;
for ( int i = 0; i < n; ++i )
for ( int k = 0; k < LOGM; ++k )
if ( (arr[i] >> k) & 1 )
mask[k] &= arr[i];
for ( int i = 0; i < LOGM; ++i ) {
if ( mask[i] == INF )
banned[i] = true;
for ( int k = i+1; k < LOGM; ++k )
if ( mask[i] == mask[k] )
banned[k] = true;
}
for ( int i = 0; i < LOGM; ++i ) {
if ( banned[i] ) continue;
for ( int k = 0; k < LOGM; ++k ) {
if ( i == k ) continue;
if ( banned[k] ) continue;
if ( (mask[i] & mask[k]) == mask[i] )
g[i].pb ( k );
}
}
}
ll to_mask[LOGM];
ll dfs_toMask ( int node ) {
assert ( node >= 0 and node < LOGM );
ll &r = to_mask[node];
if ( r != -1 ) return r;
r = 0;
for ( int it : g[node] )
r |= (1LL<<it) | dfs_toMask ( it );
return r;
}
void calcToMask () {
memset ( to_mask, -1, sizeof to_mask );
for ( int i = 0; i < LOGM; ++i ) {
if ( banned[i] ) continue;
dfs_toMask ( i );
}
}
bool isBanned ( ll c_mask ) {
assert ( c_mask >= 0 and c_mask < (1LL<<40) );
ll check_mask = 0;
for ( int i = 0; i < LOGM; ++i ) {
if ( !((c_mask>>i)&1) ) continue;
if ( banned[i] ) return true;
check_mask |= to_mask[i];
}
return (check_mask & c_mask) != 0;
}
int memo[TOT_MASK+10];
ll calcAntiChain () {
calcToMask ();
for ( int mask = 0; mask <= TOT_MASK; ++mask ) {
if ( isBanned ( mask ) ) continue;
memo[mask] = 1;
}
for ( int k = 0; k < 20; ++k )
for ( int mask = 0; mask <= TOT_MASK; ++mask )
if ( (mask>>k)&1 )
memo[mask] += memo[mask^(1<<k)];
ll ans = 0;
for ( ll mask = 0; mask <= TOT_MASK; ++mask ) {
ll true_mask = mask << 20;
if ( isBanned ( true_mask ) ) continue;
ll check_mask = 0;
for ( int i = 20; i < LOGM; ++i )
if ( (true_mask>>i)&1 )
check_mask |= to_mask[i];
check_mask = TOT_MASK & (~check_mask);
ans += memo[check_mask];
}
return ans;
}
int main () {
#ifndef LOCAL
#endif
scanf ( "%d", &n );
ll tot_and = (1LL<<LOGM)-1;
for ( int i = 0; i < n; ++i ) {
scanf ( "%lld", arr+i );
tot_and &= arr[i];
}
createGraph ();
printf ( "%lld\n", calcAntiChain () - (tot_and != 0) );
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 25ms
memory: 8980kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 24ms
memory: 8560kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 29ms
memory: 9320kb
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:
54
result:
wrong answer 1st numbers differ - expected: '52', found: '54'