QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#711500 | #7932. AND-OR closure | vwxyz | WA | 255ms | 9736kb | C++23 | 2.1kb | 2024-11-05 11:32:07 | 2024-11-05 11:32:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
signed 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
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 255ms
memory: 9736kb
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:
696767
result:
wrong answer 1st numbers differ - expected: '52', found: '696767'