QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#402439#7932. AND-OR closurechy_is_a_fishWA 1ms5692kbC++141.9kb2024-04-30 16:11:122024-04-30 16:11:12

Judging History

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

  • [2024-04-30 16:11:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5692kb
  • [2024-04-30 16:11:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5, M = (1 << 20), B = 40;
int n, m;
ll a[N], f[M], d[B], h[B], ans;
bool ok[B], g[B][B];
vector <int> ch, tp;
int main() 
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int k = 0; k < B; k++)
    {
        ll val = (1ll << 40) - 1; int cnt = 0;
        for (int i = 1; i <= n; i++) 
            if (a[i] & (1 << k))
                val &= a[i], cnt++;
        if (cnt && cnt < n)
        {
            ok[k] = 1; 
            for (int j = 0; j < 40; j++)
                if (val & (1 << j)) g[k][j] = 1;
        }
    }
    for (int k = 0; k < B; k++)
    {
        if (!ok[k]) continue;
        bool fl = 1;
        for (int j : ch)
            if (g[k][j] && g[j][k]) 
                fl = 0;
        if (fl) ch.push_back(k);
    }
    m = ch.size();
    for (int i : ch) for (int j : ch) if (g[i][j] && i != j) d[j]++;
    for (int i : ch) if (!d[i]) tp.push_back(i);
    for (int i = 0; i < m; i++) for (int j : ch)
        if (g[tp[i]][j] && tp[i] != j) if (!--d[j]) tp.push_back(j);
    for (int k = 0; k < m; k++) for (int j = 0; j < m; j++)
        if (g[tp[k]][tp[j]]) h[k] |= (1ll << j);
    int L = (m >> 1), R = m - L;
    for (int S = 0; S < (1 << R); S++)
    {
        ll val = 0;
        for (int j = 0; j < R; j++) if (S & (1 << j))
            val |= h[L+j] >> L;
        if (val == S) f[S]++;
    }
    for (int S = 1; S < (1 << R); S <<= 1)
        for (int _S = 0; _S < (1 << R); _S += (S << 1))
            for (int T = 0; T < S; T++) 
                f[_S|T] += f[S|_S|T];
    for (int S = 0; S < (1 << L); S++) 
    {
        ll val = 0;
        for (int j = 0; j < L; j++) if (S & (1 << j)) 
            val |= h[j];
        if (S == (val & (1 << L) - 1)) ans += f[val>>L];
    }
    cout << ans << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5672kb

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:

50

result:

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