QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#364439#7932. AND-OR closureucup-team004#RE 1ms3556kbC++202.8kb2024-03-24 14:30:322024-03-24 14:30:33

Judging History

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

  • [2024-03-24 14:30:33]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3556kb
  • [2024-03-24 14:30:32]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    std::vector<i64> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    int k = 40;
    std::vector g(k, std::vector<int>(k));
    std::vector<int> vis(k);

    for (int i = 0; i < k; i++) {
        i64 v = (1LL << 40) - 1;
        int cnt = 0;
        for (int j = 0; j < n; j++) {
            if (a[j] >> i & 1) {
                v &= a[j];
                cnt++;
            }
        }
        if (cnt > 0 && cnt < n) {
            vis[i] = 1;
            for (int j = 0; j < 40; j++) {
                if (v >> j & 1) {
                    g[i][j] = 1;
                }
            }
        }
    }

    std::vector<int> b;
    for (int i = 0; i < k; i++) {
        if (!vis[i]) {
            continue;
        }
        int ok = 1;
        for (auto j : b) {
            if (g[i][j] && g[j][i]) {
                ok = 0;
            }
        }
        if (ok) {
            b.push_back(i);
        }
    }
    
    n = b.size();
    std::vector<int> t;
    std::vector<int> deg(n);
    for (auto x : b) {
        for (auto y : b) {
            if (g[x][y] && x != y) {
                deg[y]++;
            }
        }
    }
    for (auto x : b) {
        if (!deg[x]) {
            t.push_back(x);
        }
    }
    for (int i = 0; i < t.size(); i++) {
        int x = t[i];
        for (auto y : b) {
            if (g[x][y] && x != y) {
                if (--deg[y] == 0) {
                    t.push_back(y);
                }
            }
        }
    }

    assert(t.size() == n);
    std::vector<i64> e(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (g[t[i]][t[j]]) {
                e[i] |= 1LL << j;
            }
        }
    }

    int n1 = n / 2;
    int n2 = n - n1;
    std::vector<int> f(1 << n2);
    for (int s = 0; s < (1 << n2); s++) {
        int v = 0;
        for (int i = 0; i < n2; i++) {
            if (s >> i & 1) {
                v |= e[n1 + i] >> n1;
            }
        }
        if (s == v) {
            f[s]++;
        }
    }

    for (int i = 1; i < (1 << n2); i *= 2) {
        for (int j = 0; j < (1 << n2); j += 2 * i) {
            for (int k = 0; k < i; k++) {
                f[j + k] += f[i + j + k];
            }
        }
    }
    i64 ans = 0;
    for (int s = 0; s < (1 << n1); s++) {
        i64 v = 0;
        for (int i = 0; i < n1; i++) {
            if (s >> i & 1) {
                v |= e[i];
            }
        }
        if (s == (v & ((1 << n1) - 1))) {
            ans += f[v >> n1];
        }
    }
    std::cout << ans << "\n";

    return 0;
}

详细

Test #1:

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

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Runtime Error

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:


result: