QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#355782#7932. AND-OR closurengpin04#RE 1ms5848kbC++144.2kb2024-03-17 08:11:342024-03-17 08:11:35

Judging History

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

  • [2024-03-17 08:11:35]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5848kb
  • [2024-03-17 08:11:34]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ALL(x) x.begin(), x.end()
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
using namespace std;

template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
    if (a > b) {a = b; return true;} return false;
};

template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
    if (a < b) {a = b; return true;} return false;
};

int n;
int sz;

long long A[200003];
long long B[200003];
vector<long long> mem[40];

//
vector<int> vec[45];

// 
vector<int> bck[45];
int cnt[45];
long long dp[45];

// is_reachable[i][j] -> j is reachable from i
bool is_reachable[45][45];

bool visited[45];
void dfs(int u, int p)
{
    is_reachable[p][u] = true;
    for(int v : vec[u])
    {
        if(is_reachable[p][v]) continue;
        dfs(v, p);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    long long SAND = bit(40)-1;
    for(int i = 1; i <= n; i++)
    {
        cin >> A[i];
        SAND &= A[i];
        for(int j = 0; j < 40; j++)
        {
            long long bit = (1LL<<j);
            if(bit&A[i])
                mem[j].push_back(A[i]);
        }
    }
    set<long long> st;
    for(int j = 0; j < 40; j++)
    {
        long long sand = (1LL<<40)-1;
        if(mem[j].size() == 0) continue;
        for(long long x : mem[j])
        {
            sand &= x;
           // cout << j << " " << x << "\n";
        }
            
        st.insert(sand);
    }
    
    for(long long x : st)
    {
        B[++sz] = x;
    }
    for(int i = 1; i <= sz; i++)
    {
        set<int> idxes = {0};
        for(int j = 1; j < i; j++)
        {
            // cout << i << " " << j << " " << (B[i]&B[j]) << '\n';
            if((B[i]&B[j]) == B[j])
            {
                for(int x : idxes)
                {
                    // cout << B[x] << " " << (B[x]&B[j]) << "\n";
                    if((B[x]&B[j]) == B[x])
                        idxes.erase(x);
                    idxes.insert(j);
                }
                
            }
        }
        for(int idx : idxes)
        {
            // cout << "EDJ : " << i << " " << idx << "\n";
            vec[i].push_back(idx);
            bck[idx].push_back(i);
            cnt[idx]++;
        }
    }
    for(int i = 0; i < 40; i++)
        dfs(i, i);

    auto solve = [&]() {
        int n = sz + 1;
        vector <long long> reach(n);
        for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (i != j && is_reachable[i][j])
                reach[i] |= bit(j), reach[j] |= bit(i);
    
        if (n == 1) {
            return 2LL;
        }

        int mid = (n >> 1);
        vector <int> dp(bit(n - mid), 0);
        for (int mask = 0; mask < bit(n - mid); mask++) {
            bool ok = true;
            for (int i = 0; i < n - mid; i++) if (getbit(mask, i)) {
                long long x = ((long long) mask << mid) & reach[i + mid];
                if (x > 0)
                    ok = false;
            }

            dp[mask] = ok;
        }

        for (int i = 0; i < n - mid; i++)
        for (int mask = 0; mask < bit(n - mid); mask++) {
            if (getbit(mask, i)) 
                dp[mask] += dp[mask ^ bit(i)];
        }

        long long tot = 0;
        for (int mask = 0; mask < bit(mid); mask++) {
            bool ok = true;
            for (int i = 0; i < mid; i++) if (getbit(mask, i)) {
                long long x = (long long) mask & reach[i];
                if (x > 0)
                    ok = false;
            }

            if (ok) {
                long long sub = 0;
                for (int i = 0; i < mid; i++) if (getbit(mask, i)) {
                    sub |= reach[i];
                }
                sub >>= mid;

                sub ^= bit(n - mid) - 1;
                // cerr << sub << "\n";
                tot += dp[sub];
            }
        }

        return tot;
    };

    long long res = solve()-1;
    if(SAND != 0) res--;
    // cout << SAND << "\n";
    cout << res << "\n";

    // cerr << log2(17179869184) << " " << bit(34) << "\n";
    return 0;
}



詳細信息

Test #1:

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

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5680kb

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5692kb

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:

52

result:

ok 1 number(s): "52"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5572kb

input:

40
32 830045728951 278250692646 1021660937663 881584025918 275993636902 275953000615 327534555567 329833558447 278293950631 327534558639 893011227647 327533244718 1021660934591 1021661000703 893011161535 1030787822591 832344731831 275994947751 1073741862 329832247598 278292639782 1030787825663 10307...

output:

44

result:

ok 1 number(s): "44"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3844kb

input:

113
995010353355 513836652779 438679050443 548477566959 507675377387 412904849600 412904919234 431506823898 1065151889147 436774574666 413152182848 438955900619 412871032896 436497750090 24159262794 419628520130 479476914639 427941630147 436493424714 412875358272 541196352 1098370744303 445117176011...

output:

143

result:

ok 1 number(s): "143"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5584kb

input:

63
274873712607 183352984580 549655082623 549688637311 463755584628 188974231516 463789156220 183487485535 274873708508 183487464532 463789160319 188907059039 463755605631 137709486080 463822782207 181339965016 274840153820 187799217236 187799238239 463789139316 146970789464 549722255100 18897421461...

output:

63

result:

ok 1 number(s): "63"

Test #7:

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

input:

46
343736386052 77314129940 1099444493311 1094075521919 68724195332 353165185622 541926877791 490604139103 404722784854 1099444493023 1094142655359 410091756246 547530709727 1094142655071 352863191638 525047822943 524980689503 524678695519 547597843167 541859744639 1099511626463 507483193951 3875417...

output:

46

result:

ok 1 number(s): "46"

Test #8:

score: 0
Accepted
time: 1ms
memory: 5664kb

input:

49
73358378052 349495737422 73358394852 74617839076 349496261711 74433224164 74616757732 377952403438 349494672878 74618363365 74432142820 74156382272 352180764143 352180223054 77302324708 74432126020 1045287271919 377952927727 360772271598 74617822276 77302848997 1039379725807 1074829312 3494946560...

output:

49

result:

ok 1 number(s): "49"

Test #9:

score: 0
Accepted
time: 1ms
memory: 5576kb

input:

55
1097313795995 1065134439323 77916805395 1028593268635 305549054739 305549054720 301254054675 1099511627775 376450620179 1030774306715 375750245147 305951707931 304942973696 302332064531 304945074944 308132746011 306627064576 9196278016 13491278099 377931283227 374672235291 307730092819 3066270645...

output:

59

result:

ok 1 number(s): "59"

Test #10:

score: -100
Runtime Error

input:

140
618955644536 618880146008 618956693368 206638591281 618954923376 618881194840 619835332946 624338984050 405244424 73492646960 628566235994 210935738169 69122164752 652800941950 632935669370 550158506048 770376204155 623249907056 551251581514 618879031632 761781682043 550024288320 624342589306 61...

output:


result: