QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691390#7932. AND-OR closureKowerKoint#Compile Error//C++202.1kb2024-10-31 11:16:492024-10-31 11:16:49

Judging History

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

  • [2024-10-31 11:16:49]
  • 评测
  • [2024-10-31 11:16:49]
  • 提交

answer

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

#define int long long
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int M = 40;
  vector<ll> B(M, 0);
  for (int b = 0; b < M; b++) {
    for (int i = 0; i < N; i++) {
      if (A[i] & 1ll << b) {
        B[b] |= 1ll << i;
      }
    }
  }
  vector<int> idx(0);
  for (int m = 0; m < M; m++) {
    if (B[m]) {
      idx.push_back(m);
    }
  }
  M = idx.size();
  vector<ll> BB(0);
  for (int m : idx) {
    BB.push_back(B[m]);
  }
  vector<vector<int>> graph(M, vector<int>(0));
  for (int b0 = 0; b0 < M; b0++) {
    for (int b1 = 0; b1 < M; b1++) {
      if (b0 == b1) {
        continue;
      }
      if ((B[b0] & B[b1]) == B[b0]) {
        graph[b1].push_back(b0);
      }
    }
  }
  int M0 = M / 2, M1 = M - M0;
  vector<ll> dp0(1 << M0, 0), dp1(1 << M1, 0);
  for (int bit = 0; bit < 1 << M0; bit++) {
    ll ok = 1ll;
    for (int b0 = 0; b0 < M0; b0++) {
      if (bit & (1 << b0)) {
        for (int b1 : graph[b0]) {
          if (b1 < M0 && !(bit & (1 << b1))) {
            ok = 0;
          }
        }
      }
    }
    dp0[bit] = ok;
  }

  for (int bit = 0; bit < 1 << M1; bit++) {
    ll ok = 1ll;
    for (int b0 = M0; b0 < N; b0++) {
      if (bit & (1 << (b0 - M0))) {
        for (int b1 : graph[b0]) {
          if (M0 <= b1 && !(bit & (1 << (b1 - M0)))) {
            ok = 0;
          }
        }
      }
    }
    dp1[bit] = ok;
  }
  for (int i = 0; i < M1; i++) {
    for (int bit = 0; bit < 1 << M1; bit++) {
      if (!(bit & (1 << i))) {
        dp1[bit] += dp1[bit | 1 << i];
      }
    }
  }
  ll ans = 0;
  for (int bit0 = 0; bit0 < 1 << M0; bit0++) {
    int bit1 = 0;
    for (int b0 = 0; b0 < M0; b0++) {
      if (bit0 & (1 << b0)) {
        for (int b1 : graph[b0]) {
          if (M0 <= b1) {
            bit1 |= 1 << (b1 - M0);
          }
        }
      }
    }
    ans += dp1[bit1];
  }
  for (int m = 0; m < M0; m++) {
    if (B[m] == 0) {
      ans /= 2;
    }
  }
  cout << ans << endl;
}

Details

cc1plus: error: ‘::main’ must return ‘int’