QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#879708 | #9980. Boolean Function Reconstruction | as_lyr | WA | 1ms | 3968kb | C++14 | 1.1kb | 2025-02-02 11:23:25 | 2025-02-02 11:23:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=16;
int n;
char s[1<<N];
bool o[1<<N];
int f[1<<N];
struct str{
int op;
string s;
};
str dfs(int x,int sum){
if(x==n){
if(o[sum])
return {1,"T"};
else
return {0,"F"};
}
str res,it;
res.op=-1;
res.s+=x+'a';
it=dfs(x+1,sum|(1<<x));
if(it.op==0)
res={0,"F"};
else if(it.op==1)
;
else{
res.s='('+res.s;
res.s+='&';
res.s+=it.s;
res.s+=')';
}
it=dfs(x+1,sum);
if(it.op==1)
res={1,"T"};
else if(it.op==0)
;
else{
res.s='('+res.s;
res.s+='|';
res.s+=it.s;
res.s+=')';
}
return res;
}
void solve(){
scanf("%d",&n);
scanf("%s",s);
for(int i=0;i<(1<<n);i++)
o[i]=s[i]-'0';
for(int i=0;i<(1<<n);i++)
f[i]=o[i];
for(int p=0;p<n;p++)
for(int i=0;i<(1<<n);i++)
if(i&(1<<p))
f[i]+=f[i^(1<<p)];
for(int i=0;i<(1<<n);i++)
if(f[i]&&o[i]==0){
puts("No");
return ;
}
for(int i=0;i<(1<<n);i++)
o[i]=f[i]==1;
puts("Yes");
str it=dfs(0,0);
cout<<it.s<<'\n';
}
int main(){
int T;
scanf("%d",&T);
while(T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3968kb
input:
7 2 0001 2 0111 2 1111 3 00010111 1 10 2 0101 5 00000000000000000000000000000001
output:
Yes (a&b) Yes (a|b) Yes T Yes ((a&(b|c))|(b&c)) No Yes a Yes (a&(b&(c&(d&e))))
result:
ok 7 lines, tightest: 4 out of 14 (7 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
4 1 00 1 10 1 01 1 11
output:
Yes F No Yes a Yes T
result:
ok 4 lines, tightest: 0 out of 11 (4 test cases)
Test #3:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
16 2 0000 2 1000 2 0100 2 1100 2 0010 2 1010 2 0110 2 1110 2 0001 2 1001 2 0101 2 1101 2 0011 2 1011 2 0111 2 1111
output:
Yes F No No No No No No No Yes (a&b) No Yes a No Yes (F|b) No Yes (a|b) Yes T
result:
ok 16 lines, tightest: 1 out of 12 (16 test cases)
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3840kb
input:
256 3 00000000 3 10000000 3 01000000 3 11000000 3 00100000 3 10100000 3 01100000 3 11100000 3 00010000 3 10010000 3 01010000 3 11010000 3 00110000 3 10110000 3 01110000 3 11110000 3 00001000 3 10001000 3 01001000 3 11001000 3 00101000 3 10101000 3 01101000 3 11101000 3 00011000 3 10011000 3 01011000...
output:
Yes F No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No ...
result:
wrong answer 5-th bit is incorrect (test case 161)