QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#372203#7932. AND-OR closuresmathasheryWA 1ms3620kbC++143.1kb2024-03-31 04:20:152024-03-31 04:20:17

Judging History

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

  • [2024-03-31 04:20:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3620kb
  • [2024-03-31 04:20:15]
  • 提交

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);
            }
        }
        cout << dependencies[b].size() << endl;
    }

    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;
}  

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3620kb

input:

4
0 1 3 5

output:

0
1
1
5

result:

wrong answer 1st numbers differ - expected: '5', found: '0'