QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372204#7932. AND-OR closuresmathasheryWA 7ms3712kbC++143.0kb2024-03-31 04:20:362024-03-31 04:20:36

Judging History

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

  • [2024-03-31 04:20:36]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3712kb
  • [2024-03-31 04:20:36]
  • 提交

answer

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <fstream>
#include <iomanip>
#include <stack>
#include <cmath>
#include <queue>
#include <assert.h>
#include <climits>
#include <functional>
#include <string>
#include <utility>
#include <unordered_set>

using namespace std;

typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef __int128_t i128;


int N;
ll arr[200000];
ll AND[200000];
vector<int> dependencies[40];
vector<int> dp;

int remove(ll num, int b){
    return ((num >> (b+1)) << b) + num % ((ll)1<<b);
}
bool has(ll num, int b){
    return ((num>>b)%2);
}


int main() {
    cin >> N;
    for(int i = 0; i < N; i++) cin >> arr[i];
    int B = 40;
    for(int b = 39; b >= 0; b--){
        bool in = false;
        bool out = false;
        for(int i = 0; i < N; i++){
            if((arr[i]>>b)%2) {
                in = true;
            }
            else out = true;
        }
        if(!(in && out)){
            for(int i = 0; i < N; i++){
                arr[i] = remove(arr[i], b);
            }
            B--;
        }
    }
    for(int b = 0; b < B; b++){
        ll msk = ((ll)1 << 40) - 1;
        for(int i = 0; i < N; i++){
            if((arr[i]>>b)%2) {
                msk &= arr[i];
            }
        }
        for(int b2 = 0; b2 < B; b2++){
            if(b2 != b && (msk>>b2)%2){
                dependencies[b].push_back(b2);
            }
        }
    }

    if(B == 1){
        cout << 2 << endl;
        return 0;
    }
    else if(B == 0){
        cout << 1 << endl;
        return 0;
    }
    dp = vector<int>(1<<(B/2));
    for(int msk = 1; msk < (1<<(B/2)); msk++){
        bool works = true;
        for(int b = 0; b < B/2; b++){
            if(!has(msk, b)) continue;
            for(int b2 : dependencies[b]){
                if(b2 < B/2) works = works && has(msk, b2);
            }
        }
        if(works) {
            dp[msk] = 1;
            //cout << msk << endl;
        }
    }
    for(int i = 0; i < N; i++) if(arr[i] == 0) dp[0] = 1;
    for(int b = 0; b < B/2; b++){
        for(int msk = 0; msk < (1<<(B/2)); msk++){
            if(!has(msk, b)){
                dp[msk] += dp[msk+((ll)1<<b)];
            }
        }
    }

    ll res = 0;

    for(int msk = 0; msk < (1<<((B+1)/2)); msk++){
        ll M = (ll)msk << (B/2);
        ll dm = 0;
        bool works = true;
        for(int b = B/2; b < B; b++){
            if(has(M, b)){
                for(int b2 : dependencies[b]){
                    if(b2 < B/2){
                        dm |= (1<<b2);
                    }
                    else if(!has(M, b2)){
                        works = false;
                    }
                }
            }
        }
        if(works) res += dp[dm];
    }
    cout << res << endl;
    
    return 0;
}  

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Wrong Answer
time: 7ms
memory: 3604kb

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:

646

result:

wrong answer 1st numbers differ - expected: '52', found: '646'