QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#332091#7932. AND-OR closureUNos_maricones#WA 31ms12400kbC++142.9kb2024-02-19 08:35:302024-02-19 08:35:30

Judging History

你现在查看的是最新测评结果

  • [2024-02-19 08:35:30]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:12400kb
  • [2024-02-19 08:35:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back

typedef long long ll;
typedef pair <ll,ll> pii;

const ll N = 200'005;
const ll LOGM = 40;
const ll INF = (1LL<<41)-1LL;
const ll TOT_MASK = (1<<20)-1;

ll arr[N];
ll n;

ll mask[LOGM];
bool banned[LOGM];
vector <ll> g[LOGM];

void createGraph () {
    for ( ll i = 0; i < LOGM; ++i )
        mask[i] = INF;
    for ( ll i = 0; i < n; ++i )
        for ( ll k = 0; k < LOGM; ++k )
            if ( (arr[i] >> k) & 1LL )
                mask[k] &= arr[i];
    for ( ll i = 0; i < LOGM; ++i ) {
        if ( mask[i] == INF )
            banned[i] = true;
        for ( ll k = i+1; k < LOGM; ++k )
            if ( mask[i] == mask[k] )
                banned[k] = true;
    }
    for ( ll i = 0; i < LOGM; ++i ) {
        if ( banned[i] ) continue;
        for ( ll 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 ( ll node ) {
    assert ( node >= 0 and node < LOGM );
    ll &r = to_mask[node];
    if ( r != -1 ) return r;
    r = 0;
    for ( ll it : g[node] )
        r |= (1LL<<it) | dfs_toMask ( it );
    return r;
}

void calcToMask () {
    memset ( to_mask, -1, sizeof to_mask );
    for ( ll 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 ( ll i = 0; i < LOGM; ++i ) {
        if ( !((c_mask>>i)&1LL) ) continue;
        if ( banned[i] ) return true;
        check_mask |= to_mask[i];
    }
    return (check_mask & c_mask) != 0;
}

ll memo[TOT_MASK+10];

ll calcAntiChain () {
    calcToMask ();
    for ( ll mask = 0; mask <= TOT_MASK; ++mask ) {
        if ( isBanned ( mask ) ) continue;
        memo[mask] = 1;
    }
    for ( ll k = 0; k < 20; ++k )
        for ( ll mask = 0; mask <= TOT_MASK; ++mask ) 
            if ( (mask>>k)&1 )
                memo[mask] += memo[mask^(1LL<<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 ( ll i = 20; i < LOGM; ++i )
            if ( (true_mask>>i)&1LL )
                check_mask |= to_mask[i];
        check_mask = TOT_MASK & (~check_mask);
        ans += memo[check_mask];
    }
    return ans;
}

int main () {
        
    #ifndef LOCAL
    #endif

    scanf ( "%lld", &n );

    ll tot_and = (1LL<<LOGM)-1;
    for ( ll 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: 29ms
memory: 12400kb

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 24ms
memory: 12020kb

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Wrong Answer
time: 31ms
memory: 12308kb

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'