QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#861326 | #9980. Boolean Function Reconstruction | ucup-team191# | WA | 0ms | 3584kb | C++23 | 1.1kb | 2025-01-18 16:57:41 | 2025-01-18 16:58:20 |
Judging History
answer
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define x first
#define y second
#define pb push_back
#define all(a) begin(a),end(a)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
using pii=pair<int,int>;
const int N = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const char en='\n';
const ll LLINF=1ll<<60;
string f(string s,int off)
{
if (s.size()==2)
{
if (s=="00") return "F";
if (s=="01") return string(1,'a'+off);
if (s=="11") return "T";
assert(0);
}
int cl=s.size();
return "("+f(s.substr(0,cl/2),off-1)+"|("+string(1,'a'+off)+"&"+f(s.substr(cl/2),off-1)+"))";
}
int t,n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>t;
while (t--)
{
cin>>n;
string s;
cin>>s;
bool ok=1;
for (int b=0;b<n;++b) for (int i=0;i<(1<<n);++i) if ((i>>b)&1)
{
if (s[i^(1<<b)]=='1' && s[i]=='0') ok=0;
}
//cout<<n<<' '<<s<<endl;
if (!ok)
{
cout<<"No\n";
//cout<<flush;
continue;
}
cout<<"Yes\n";
//cout<<flush;
cout<<f(s,n-1)<<en;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3584kb
input:
7 2 0001 2 0111 2 1111 3 00010111 1 10 2 0101 5 00000000000000000000000000000001
output:
Yes (F|(b&a)) Yes (a|(b&T)) Yes (T|(b&T)) Yes ((F|(b&a))|(c&(a|(b&T)))) No Yes (a|(b&a)) Yes ((((F|(b&F))|(c&(F|(b&F))))|(d&((F|(b&F))|(c&(F|(b&F))))))|(e&(((F|(b&F))|(c&(F|(b&F))))|(d&((F|(b&F))|(c&(F|(b&a))))))))
result:
wrong answer 30 operations, you can't use more than 26 operations (test case 7)