QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328756 | #7932. AND-OR closure | egrr | WA | 1ms | 3944kb | C++14 | 2.5kb | 2024-02-16 05:44:40 | 2024-02-16 05:44:42 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define B 40
#define M ((1<<20)+10)
int n;
bool rec[B][B][2][2];
bool fl[B][2];
int id[B], tot;
ll out[B];
ll dp[M];
void dypro() {
int b = tot/2;
ll full = (1<<b)-1;
for(ll 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(ll j=0;j<=full;++j) if((j>>i)&1) {
dp[j^(1<<i)] += dp[j];
}
}
ll ans = 0;
ll full2 = ((1ll<<tot)-1)^full;
for(ll i=0;i<=(full2>>b);++i) {
ll 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("%lld\n", ans);
}
int main(void) {
scanf("%d", &n);
for(int i=0;i<n;++i) {
ll t; scanf("%lld", &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;
continue;
}
id[i] = -2;
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 && rec[i][j][0][0]) id[j] = -1;
}
}
for(int k=0;k<B;++k) {
for(int i=0;i<B;++i) if(id[i] == -2) {
bool fl = true;
for(int j=i+1;j<B;++j) if(id[j] == -2) {
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 && rec[i][j][0][1] == false) fl = false;
}
if(fl) id[i] = tot++;
}
}
for(int i=0;i<B;++i) if(~id[i]) id[i] = tot-id[i]-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];
}
}
}
// cerr<<tot<<"!"<<endl;
if(tot == 0) {
printf("0\n");
return 0;
} else if(tot == 1) {
printf("2\n");
return 0;
}
dypro();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3796kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3944kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3888kb
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:
52
result:
ok 1 number(s): "52"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
40 32 830045728951 278250692646 1021660937663 881584025918 275993636902 275953000615 327534555567 329833558447 278293950631 327534558639 893011227647 327533244718 1021660934591 1021661000703 893011161535 1030787822591 832344731831 275994947751 1073741862 329832247598 278292639782 1030787825663 10307...
output:
44
result:
ok 1 number(s): "44"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3868kb
input:
113 995010353355 513836652779 438679050443 548477566959 507675377387 412904849600 412904919234 431506823898 1065151889147 436774574666 413152182848 438955900619 412871032896 436497750090 24159262794 419628520130 479476914639 427941630147 436493424714 412875358272 541196352 1098370744303 445117176011...
output:
166
result:
wrong answer 1st numbers differ - expected: '143', found: '166'