QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328146 | #7932. AND-OR closure | egrr | WA | 0ms | 3924kb | C++14 | 2.2kb | 2024-02-15 17:36:48 | 2024-02-15 17:36:49 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef unsigned long long ull;
#define B 40
#define M ((1<<20)+10)
int n;
bool rec[B][B][2][2];
bool fl[B][2];
int id[B], tot, b;
ull out[B];
void upd(int u) {
for(int i=0;i<tot;++i) if(out[u]>>i&1) {
upd(i);
out[u] |= out[i];
}
}
int dp[M];
void dypro() {
ull full = (1<<b)-1;
for(ull i=0;i<=full;++i) {
bool fl = true;
for(int j=0;j<b;++j) if(i>>j&1) {
if(((out[j]&full)|i)>i) {
fl = false;
break;
}
}
if(fl) dp[i] = 1;
}
for(int i=0;i<b;++i) {
for(ull j=0;j<=full;++j) if(j>>i&1) {
dp[j^(1<<i)] += dp[j];
}
}
ull ans = 0;
ull full2 = ((1ull<<tot)-1)^full;
for(ull i=0;i<=full2>>b;++i) {
ull st = i<<b, to = 0;
bool fl = true;
for(int j=b;j<tot;++j) if(st>>j&1) {
if(((out[j]&full2)|st)>st) {
fl = false;
break;
} else {
to |= out[j]&full;
}
}
if(fl) ans += dp[to];
}
printf("%llu\n", ans);
}
int main(void) {
scanf("%d", &n);
for(int i=0;i<n;++i) {
ull t; scanf("%llu", &t);
for(int j=0;j<B;++j) {
fl[j][t>>j&1] = 1;
for(int k=j+1;k<B;++k) {
rec[j][k][t>>j&1][t>>k&1] = 1;
}
}
}
for(int i=0;i<B;++i) if(~id[i]) {
if(!(fl[i][0] && fl[i][1])) {
id[i] = -1;
}
id[i] = tot++;
for(int j=i+1;j<B;++j) if(~id[j]) {
int sm = (int)rec[i][j][0][0] + (int)rec[i][j][0][1] + (int)rec[i][j][1][0] + (int)rec[i][j][1][1];
if(sm == 2) {
if(rec[i][j][0][0]) {
id[j] = -1;
}
}
}
}
for(int i=0;i<B;++i) if(~id[i]) {
for(int j=i+1;j<B;++j) if(~id[j]) {
int sm = (int)rec[i][j][0][0] + (int)rec[i][j][0][1] + (int)rec[i][j][1][0] + (int)rec[i][j][1][1];
if(sm == 3) {
if(rec[i][j][0][1] == false) {
out[id[j]] |= 1<<id[i];
} else if(rec[i][j][1][0] == false) {
out[id[i]] |= 1<<id[j];
}
}
}
}
if(tot == 0) {
printf("0\n");
return 0;
} else if(tot == 1) {
printf("2\n");
return 0;
}
b = tot/2;
for(int i=0;i<tot;++i) upd(i);
dypro();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3920kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3924kb
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:
784
result:
wrong answer 1st numbers differ - expected: '52', found: '784'