QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#705918#7932. AND-OR closureohiostatescarlet#WA 0ms3848kbC++171.9kb2024-11-03 04:03:102024-11-03 04:03:15

Judging History

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

  • [2024-11-03 04:03:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3848kb
  • [2024-11-03 04:03:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll BIT = 40;
vector<int> component;
int find(int x) {
    return (component[x] < 0) ? x : (component[x] = find(component[x]));
}
bool join(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (component[x] > component[y]) swap(x,y);
    component[x] += component[y];
    component[y] = x;
    return true;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    int n; cin >> n;
    bool hasZero = false;
    vector<ll> vals(n, 0);
    component.assign(BIT, -1);
    vector<vector<bool>> edges(BIT, vector<bool>(BIT, false));
    int comp = -1;
    ll scl = 2;
    ll msk = 0;
    for (int i = 0; i < n; i++) {
        ll v; cin >> v;
        vals[i] = v;
        if (v == 0) hasZero = true;
        vector<int> unset;
        vector<int> set;
        for (int j = 0; j < BIT; j++) {
            if ((v>>j)&1) {
                set.push_back(j);
            } else {
                unset.push_back(j);
            }
        }
        for (int a : set) for (int b : unset) {
            edges[a][b] = true;
            if (edges[b][a]) {
                if (join(a,b)) {
                    comp = a;
                    scl *= 2;
                    msk |= (1ll << a) | (1ll << b);
                }
            }
        }
    }
    ll msk2 = msk;
    for (int i = 0; i < BIT; i++) {
        for (int j = 0; j < BIT; j++) {
            if (edges[i][j] && component[find(j)] < -1) {
                msk2 |= (1ll << i);
            }
        }
    }
    // cout << msk << " " << msk2 << "\n";
    ll res = scl;
    for (ll v : vals) {
        if (v != msk2 && v != (msk^msk2) && ((v&msk) == 0 || (v&msk2)==msk2)) {
            // cout << v << "++\n";
            res++;
        }
    }
    cout << res << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

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:

68719476736

result:

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