QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#355717#7932. AND-OR closurepipoika#WA 1ms3904kbC++172.0kb2024-03-17 04:14:102024-03-17 04:14:12

Judging History

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

  • [2024-03-17 04:14:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3904kb
  • [2024-03-17 04:14:10]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,j,k) for (int i=j;i<(k);++i)
#define all(i) (i).begin(), (i).end()
#define sz(i) (int)(i).size()
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long long ll;

typedef vector<ll> vll;

vll deps;
int split;
vll shifts;
vll left_side;

ll masker;
ll ans = 0;

void masks(ll cur, int bit) {
    if (bit == split) {
        // cout << ' ' << cur << endl;
        ++left_side[cur];
        return;
    }
    if ((cur & shifts[bit])) masks(cur^shifts[bit], bit+1);
    masks(cur, bit+1);
}

void step1(ll cur, int bit) {
    if (bit < 0) {
        masks(cur, 0);
        return;
    }
    if ((cur&shifts[bit]) == 0) step1(cur|deps[bit], bit-1);
    step1(cur, bit-1);
}

void generate(ll cur, int bit) {
    if (bit < split) {
        ll masked = cur&masker;
        ans += left_side[masked];

        // cout << cur << ' ' << left_side[masked] << endl;

        // TODO
        return;
    }
    if ((cur&shifts[bit]) == 0) generate(cur|deps[bit], bit-1);
    generate(cur, bit-1);
}

int main() {
    int n;
    int _;
    _=scanf("%d",&n);

    vll nums(n);
    rep(i,0,n) _=scanf("%lld",&nums[i]);

    ll bit=1;
    set<ll> dups;
    rep(p,0,40) {
        ll sub = -1;
        for (auto x : nums) if (x&bit) sub&=x;
        if (~sub) dups.insert(sub);
        bit<<=1;
    }

    if (sz(dups) == 0) {
        cout << "1\n";
        return 0;
    }

    vll vals;
    for (auto x : dups) vals.push_back(x);

    int m=sz(dups);
    deps.assign(m, 0);

    shifts.assign(m,0);
    shifts[0]=1;
    rep(i,1,m) shifts[i]=shifts[i-1]<<1;

    rep(i,0,m) rep(j,0,i+1) {
        if ((vals[i]&vals[j]) == vals[j]) deps[i]|=shifts[j];
    }

    split=max(0,m-25); //MUST ADD RTHIS Back
    // split = 1;

    masker = (1<<split) - 1;

    left_side.assign(1<<split, 0);

    step1(0, split-1);

    generate(0L, m-1);

    cout << ans << endl;


    return 0;
}

詳細信息

Test #1:

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

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

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:

53

result:

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