QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#349049#7932. AND-OR closureec1117WA 0ms3756kbC++143.3kb2024-03-09 23:20:132024-03-09 23:20:13

Judging History

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

  • [2024-03-09 23:20:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3756kb
  • [2024-03-09 23:20:13]
  • 提交

answer

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

#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define f first
#define s second

#define FOR(i,a,b) for(int i=a;i<b;i++) 
#define For(i,a) FOR(i,0,a)
#define trav(a,b) for(auto& a:b)
#define pi pair<int,int>
#define vi vector<int>
#define vl vector<ll>

const int MX = 2e5+5;
const int MOD = 1e9+7;
const ll INF = 1e18;

ll a[MX];
set<int> reps[40];
bool done[40];
vi todo[42];
ll ans[44];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n;cin>>n;
    bool hasZero = false;
    For(i,n) {
        cin>>a[i];
        if(!a[i]) {
            hasZero = true;
        }
    }
    if (n==1 && hasZero) {
        cout << 1 << endl;
        return 0;
    }
    ll t2 = a[0]==0?a[1]:a[0];
    For(i,n) {
        if(a[i]!=0)
            t2 &= a[i];
    }
    int zz = 42;
    if(t2) {
        int mx = -1;
        For(k,40) if(t2 & (1LL<<k)) {
            mx = k;
        }
        ans[mx] = 1;
        zz= mx;
    } else {
        ans[42] = 1;
    }

    For(i,40) {
        ll tmp = -1;
        bool allHave = true;
        For(j,n) {
            if(a[j] & (1LL<<i)) {
                if(tmp==-1) {
                    tmp=a[j];
                } else {
                    tmp &= a[j];
                }
            } else {
                allHave = false;
            }
        }
        if(tmp!=-1 && !allHave) {
            // cout << "A " << tmp << endl;
            For(k,40) if(tmp & (1LL<<k)) {
                // cout << "B " << i << " " << k << endl;
                reps[i].insert(k);
            }
            // cout << "ADD: " << i << endl;
            todo[reps[i].size()].pb(i);
            ans[i] = 1;
        }
    }
    // ans[42] = 1;
    // ll ans = 1;

    // For(i,44)ans[i] = 1;
    for(int i=41;i>=0;i--) {
        vector<bool> done(42);
        vi tmp = todo[i];
        reverse(tmp.begin(), tmp.end());
        trav(x,tmp) if(!done[x]) {
            pi tmp = {0,42};
            trav(y,reps[x]) if(reps[y].size() < reps[x].size()){
                tmp = max(tmp, {reps[y].size(),y});
            }
            trav(z,reps[x]) {
                done[z] = true;
            }
            int PAR = tmp.s;
            ans[PAR] *= (1+ans[x]);
            // cout << "C " << i << " " << tmp.f << " " << tmp.f2 << " " << tmp.s << endl;
            // cout << "D " << x << " " << ans[x] << endl;
        }

    }

    int add = 0;
    if(zz!=42 && hasZero)
        add = 1;
    cout << ans[zz] + add << endl;

    // For(i,40)if(!done[i]) {
    //     vector<set<int>> tmp;
    //     tmp.insert(reps[i]);
    //     vi vv;
    //     vv.pb(i);
    //     done[i] = true;
    //     trav(x,reps[i]) {
    //         tmp.insert(reps[x]);
    //     }
    //     For(j,40) if(i!=j) {
    //         bool ok = false;
    //         trav(x,reps[j])if(x==i) {
    //             ok = true;
    //         }
    //         if(ok) {
    //             tmp.insert(reps[j]);
    //             done[j] = true;
    //             vv.pb(j);
    //         }
    //     }
    //     trav(x,vv) {
    //         cout << i << " " << x << endl;
    //     }
    // }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3756kb

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3540kb

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:

1

result:

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