QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#862526#9980. Boolean Function Reconstructionucup-team1134#TL 1958ms15616kbC++2310.6kb2025-01-19 02:32:372025-01-19 02:32:37

Judging History

你现在查看的是最新测评结果

  • [2025-01-19 02:32:37]
  • 评测
  • 测评结果:TL
  • 用时:1958ms
  • 内存:15616kb
  • [2025-01-19 02:32:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

string AND(vi pos){
    if(si(pos)==0) return "T";
    else if(si(pos)==1) return string(1,char('a'+pos[0]));
    else{
        vi A,B;
        for(int i=0;i<si(pos);i++){
            if(i<si(pos)/2) A.pb(pos[i]);
            else B.pb(pos[i]);
        }
        auto aa=AND(A),bb=AND(B);
        string res;
        res+='(';
        res+=aa;
        res+='&';
        res+=bb;
        res+=')';
        return res;
    }
}

string OR(vst pos){
    if(si(pos)==0) return "F";
    else if(si(pos)==1) return pos[0];
    else{
        vst A,B;
        for(int i=0;i<si(pos);i++){
            if(i<si(pos)/2) A.pb(pos[i]);
            else B.pb(pos[i]);
        }
        auto aa=OR(A),bb=OR(B);
        string res;
        res+='(';
        res+=aa;
        res+='|';
        res+=bb;
        res+=')';
        return res;
    }
}

string solve(int N,string S){
    vst ans;
    string U(1<<N,'0');
    vi iru(1<<N);
    for(int bit=0;bit<(1<<N);bit++){
        bool ok=true;
        int rem=(1<<N)-1-bit;
        for(int T=rem;;T=(T-1)&rem){
            ok&=(S[bit|T]=='1');
            if(T==0) break;
        }
        if(ok){
            iru[bit]=true;
            for(int T=rem;;T=(T-1)&rem){
                U[bit|T]='1';
                if(T==0) break;
            }
        }
    }
    
    if(U==S){
        
        for(int bit=(1<<N)-1;bit>=0;bit--){
            if(iru[bit]){
                bool kesu=true;
                for(int i=0;i<N;i++){
                    if(bit&(1<<i)){
                        kesu&=(iru[bit^(1<<i)]);
                    }
                }
                //if(kesu) iru[bit]=false;
            }
        }
        for(int bit=0;bit<(1<<N);bit++){
            if(iru[bit]){
                vi fff;
                for(int i=0;i<N;i++){
                    if(bit&(1<<i)) fff.pb(i);
                }
                ans.pb(AND(fff));
            }
        }
        for(int i=0;i<N;i++){
            for(int bit=0;bit<(1<<N);bit++){
                if(!(bit&(1<<i))){
                    chmax(U[bit|(1<<i)],U[bit]);
                }
            }
        }
        assert(U==S);
        return OR(ans);
    }else{
        U=S;
        for(int i=0;i<N;i++){
            for(int bit=0;bit<(1<<N);bit++){
                if(!(bit&(1<<i))){
                    chmax(U[bit|(1<<i)],U[bit]);
                }
            }
        }
        assert(U!=S);
        return "NG";
    }
}
string X;
map<string,string> MA;
string DFS(string S,int u){
    if(u==3&&si(X)){
        //assert(MA.count(S));
        return MA[S];
    }
    if(u==2){
        if(S=="00010011") return "(b&(a|c))";
        if(S=="00010101") return "(a&(b|c))";
        if(S=="00110111") return "(b|(a&c))";
        if(S=="01010111") return "(a|(b&c))";
    }
    if(u==1){
        if(S=="0000") return "F";
        if(S=="0001") return "(b&a)";
        if(S=="0011") return "b";
        if(S=="0101") return "a";
        if(S=="0111") return "(b|a)";
        if(S=="1111") return "T";
        return "";
    }
    if(u==0){
        if(S=="00") return "F";
        else if(S=="11") return "T";
        else if(S=="01") return "a";
        else{
            //cout<<X<<endl;
            exit(1);
            return "oh";
        }
    }else{
        string A,B;
        for(int bit=0;bit<si(S)/2;bit++){
            if(S[bit]=='0'){
                if(S[bit+si(S)/2]=='0'){
                    A+='0';
                    B+='0';
                }else{
                    A+='1';
                    B+='0';
                }
            }else{
                if(S[bit+si(S)/2]=='0'){
                    //cout<<X<<endl;
                    exit(1);
                }else{
                    A+='1';
                    B+='1';
                }
            }
        }
        
        if(A==B){
            auto aa=DFS(A,u-1);
            return aa;
        }
        
        auto aa=DFS(A,u-1),bb=DFS(B,u-1);
        if(aa=="F"){
            return bb;
        }
        if(aa=="T"){
            if(bb=="T"){
                return "T";
            }
            if(bb=="F"){
                return string(1,char('a'+u));
            }
            string Z;
            Z+='(';
            Z+=char('a'+u);
            Z+='|';
            Z+=bb;
            Z+=')';
            return Z;
        }
        if(bb=="F"){
            string Z;
            Z+='(';
            Z+=char('a'+u);
            Z+='&';
            Z+=aa;
            Z+=')';
            return Z;
        }
        if(bb=="T"){
            return "T";
        }
        string Z;
        Z+='(';
        Z+='(';
        Z+=char('a'+u);
        Z+='&';
        Z+=aa;
        Z+=')';
        Z+='|';
        Z+=bb;
        Z+=')';
        return Z;
    }
}

string solve2(int N,string S){
    string U=S;
    for(int i=0;i<N;i++){
        for(int bit=0;bit<(1<<N);bit++){
            if(!(bit&(1<<i))){
                chmax(U[bit|(1<<i)],U[bit]);
            }
        }
    }
    if(U!=S) return "NG";
    return DFS(S,N-1);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string solve3(int N,string S){
    pair<int,string> re=mp(INF,"");
    for(int q=0;q<20;q++){
        vi id(N);iota(all(id),0);
        shuffle(all(id),rng);
        string nex(1<<N,'0');
        for(int i=0;i<(1<<N);i++){
            if(S[i]=='1'){
                int to=0;
                for(int j=0;j<N;j++){
                    if(i&(1<<j)) to|=(1<<id[j]);
                }
                nex[to]='1';
            }
        }
        auto aa=solve2(N,nex);
        int cn=0;
        for(int i=0;i<si(aa);i++){
            if(aa[i]=='|'||aa[i]=='&') cn++;
        }
        string bb;
        vi inv(N);
        for(int i=0;i<N;i++){
            inv[id[i]]=i;
        }
        for(int i=0;i<si(aa);i++){
            if('a'<=aa[i]&&aa[i]<='z'){
                bb+=char('a'+(inv[aa[i]-'a']));
            }else{
                bb+=aa[i];
            }
        }
        chmin(re,mp(cn,bb));
    }
    return re.se;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    for(int N=4;N<=4;N++){
        for(ll bit=0;bit<(1LL<<(1LL<<N));bit++){
            string S;
            for(int i=0;i<(1LL<<N);i++){
                if(bit&(1LL<<((1LL<<N)-1-i))) S+='1';
                else S+='0';
            }
            auto a=solve2(N,S);
            if(a=="NG") continue;
            auto aa=solve3(N,S);
            int cn=0;
            for(int i=0;i<si(aa);i++){
                if(a[i]=='|'||a[i]=='&') cn++;
            }
            
            //cout<<"if(S=="<<'"'<<S<<'"'<<") return "<<'"'<<aa<<'"'<<";\n";
            MA[S]=aa;
            //cout<<S<<" "<<aa<<endl;
            //cout<<N<<" "<<cn<<" "<<S<<endl;
        }
    }
    X="DONE";
    /*
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
    int ma=0;
    while(1){
        int N=8;
        string S(1<<N,'0');
        for(int bi=0;bi<(1<<N);bi++){
            int z=rand()%10;
            if(z==0){
                for(int y=0;y<(1<<N);y++){
                    if((y&bi)==bi) S[y]='1';
                }
            }
        }
        auto a=solve2(N,S);
        if(a=="NG") continue;
        pair<int,string> re=mp(INF,"");
        for(int q=0;q<20;q++){
            vi id(N);iota(all(id),0);
            shuffle(all(id),rng);
            string nex(1<<N,'0');
            for(int i=0;i<(1<<N);i++){
                if(S[i]=='1'){
                    int to=0;
                    for(int j=0;j<N;j++){
                        if(i&(1<<j)) to|=(1<<id[j]);
                    }
                    nex[to]='1';
                }
            }
            auto aa=solve2(N,nex);
            int cn=0;
            for(int i=0;i<si(aa);i++){
                if(aa[i]=='|'||aa[i]=='&') cn++;
            }
            chmin(re,mp(cn,nex));
        }
        int cn=0;
        for(int i=0;i<si(a);i++){
            if(a[i]=='|'||a[i]=='&') cn++;
        }
        cn=re.fi;
        if(chmax(ma,cn)) cout<<ma<<" "<<(1<<(N-1))+10<<" "<<a<<" "<<S<<endl;
        //cout<<N<<" "<<ma<<" "<<(1<<(N-1))+10<<endl;
    }
     */
    int Q;cin>>Q;
    while(Q--){
        int N;cin>>N;
        string S;cin>>S;
        auto ans=solve(N,S);
        if(ans=="NG") cout<<"No\n";
        else{
            cout<<"Yes\n";
            while(1){
                vi id(N);iota(all(id),0);
                shuffle(all(id),rng);
                string nex(1<<N,'0');
                for(int i=0;i<(1<<N);i++){
                    if(S[i]=='1'){
                        int to=0;
                        for(int j=0;j<N;j++){
                            if(i&(1<<j)) to|=(1<<id[j]);
                        }
                        nex[to]='1';
                    }
                }
                auto aa=solve2(N,nex);
                int cn=0;
                for(int i=0;i<si(aa);i++){
                    if(aa[i]=='|'||aa[i]=='&') cn++;
                }
                if(cn<=((1<<(N-1))+10)){
                    vi inv(N);
                    for(int i=0;i<N;i++){
                        inv[id[i]]=i;
                    }
                    for(int i=0;i<si(aa);i++){
                        if('a'<=aa[i]&&aa[i]<='z'){
                            cout<<char('a'+(inv[aa[i]-'a']));
                        }else{
                            cout<<aa[i];
                        }
                    }
                    cout<<"\n";
                    break;
                }
            }
        }
    }
}



詳細信息

Test #1:

score: 100
Accepted
time: 15ms
memory: 3840kb

input:

7
2
0001
2
0111
2
1111
3
00010111
1
10
2
0101
5
00000000000000000000000000000001

output:

Yes
(a&b)
Yes
(b|a)
Yes
T
Yes
((b&(c|a))|(c&a))
No
Yes
a
Yes
(e&(d&(b&(a&c))))

result:

ok 7 lines, tightest: 4 out of 14 (7 test cases)

Test #2:

score: 0
Accepted
time: 14ms
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: 14ms
memory: 3712kb

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
b
No
Yes
(b|a)
Yes
T

result:

ok 16 lines, tightest: 1 out of 12 (16 test cases)

Test #4:

score: 0
Accepted
time: 16ms
memory: 3456kb

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:

ok 256 lines, tightest: 4 out of 14 (256 test cases)

Test #5:

score: 0
Accepted
time: 38ms
memory: 3712kb

input:

65536
4
0000000000000000
4
1000000000000000
4
0100000000000000
4
1100000000000000
4
0010000000000000
4
1010000000000000
4
0110000000000000
4
1110000000000000
4
0001000000000000
4
1001000000000000
4
0101000000000000
4
1101000000000000
4
0011000000000000
4
1011000000000000
4
0111000000000000
4
1111000...

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:

ok 65536 lines, tightest: 8 out of 18 (65536 test cases)

Test #6:

score: 0
Accepted
time: 15ms
memory: 3840kb

input:

168
4
0000000000000000
4
0000000000000001
4
0000000000000011
4
0000000000000101
4
0000000000000111
4
0000000000001111
4
0000000000010001
4
0000000000010011
4
0000000000010101
4
0000000000010111
4
0000000000011111
4
0000000000110011
4
0000000000110111
4
0000000000111111
4
0000000001010101
4
000000000...

output:

Yes
F
Yes
(b&(c&(d&a)))
Yes
(b&(c&d))
Yes
(c&(d&a))
Yes
(d&(c&(b|a)))
Yes
(c&d)
Yes
(b&(d&a))
Yes
(b&(d&(c|a)))
Yes
(d&(a&(b|c)))
Yes
(d&((a&(c|b))|(c&b)))
Yes
(d&(c|(b&a)))
Yes
(b&d)
Yes
(d&(b|(c&a)))
Yes
(d&(c|b))
Yes
(d&a)
Yes
(d&(a|(c&b)))
Yes
(d&(c|a))
Yes
(d&(a|b))
Yes
(d&(b|(a|c)))
Yes
d
Yes
...

result:

ok 168 lines, tightest: 8 out of 18 (168 test cases)

Test #7:

score: 0
Accepted
time: 94ms
memory: 3840kb

input:

7581
5
00000000000000000000000000000000
5
00000000000000000000000000000001
5
00000000000000000000000000000011
5
00000000000000000000000000000101
5
00000000000000000000000000000111
5
00000000000000000000000000001111
5
00000000000000000000000000010001
5
00000000000000000000000000010011
5
0000000000000...

output:

Yes
F
Yes
(a&(d&(e&(b&c))))
Yes
(d&(b&(e&c)))
Yes
(a&(d&(e&c)))
Yes
(c&(e&(d&(a|b))))
Yes
(d&(c&e))
Yes
(b&(d&(e&a)))
Yes
(d&(e&(b&(c|a))))
Yes
((c&(e&(d&a)))|(e&(a&(d&b))))
Yes
(d&(e&((b&(c|a))|(c&a))))
Yes
(d&(e&(c|(a&b))))
Yes
(d&(b&e))
Yes
((b&(d&e))|(d&(a&(e&c))))
Yes
((b&(e&d))|(e&(d&c)))
Yes
...

result:

ok 7581 lines, tightest: 18 out of 26 (7581 test cases)

Test #8:

score: 0
Accepted
time: 65ms
memory: 8884kb

input:

14
1
01
2
0111
3
00010111
4
0001011101111111
5
00000001000101110001011101111111
6
0000000100010111000101110111111100010111011111110111111111111111
7
00000000000000010000000100010111000000010001011100010111011111110000000100010111000101110111111100010111011111110111111111111111
8
00000000000000010000...

output:

Yes
a
Yes
(a|b)
Yes
((b&(c|a))|(c&a))
Yes
((a&(d|(b|c)))|((d&(b|c))|(b&c)))
Yes
((e&((c&(d|(b|a)))|((d&(b|a))|(b&a))))|((c&((a&(d|b))|(d&b)))|(a&(d&b))))
Yes
((d&((e&(c|(f|(a|b))))|((c&(f|(b|a)))|((f&(b|a))|(b&a)))))|((e&((c&(f|(b|a)))|((f&(b|a))|(b&a))))|((c&((a&(f|b))|(f&b)))|(a&(f&b)))))
Yes
((g&...

result:

ok 14 lines, tightest: 68 out of 74 (14 test cases)

Test #9:

score: 0
Accepted
time: 54ms
memory: 7308kb

input:

14
1
01
2
0001
3
00010111
4
0000000100010111
5
00000001000101110001011101111111
6
0000000000000001000000010001011100000001000101110001011101111111
7
00000000000000010000000100010111000000010001011100010111011111110000000100010111000101110111111100010111011111110111111111111111
8
00000000000000000000...

output:

Yes
a
Yes
(b&a)
Yes
((c&(b|a))|(b&a))
Yes
((a&((d&(b|c))|(b&c)))|(d&(b&c)))
Yes
((b&((a&(d|(e|c)))|((d&(e|c))|(e&c))))|((a&((e&(c|d))|(c&d)))|(e&(c&d))))
Yes
((a&((d&((c&(b|(e|f)))|((b&(e|f))|(e&f))))|((c&((e&(f|b))|(f&b)))|(e&(f&b)))))|((d&((c&((e&(f|b))|(f&b)))|(e&(f&b))))|(c&(b&(e&f)))))
Yes
((a&...

result:

ok 14 lines, tightest: 68 out of 74 (14 test cases)

Test #10:

score: 0
Accepted
time: 49ms
memory: 7168kb

input:

14
1
00
2
0001
3
00000001
4
0000000100010111
5
00000000000000010000000100010111
6
0000000000000001000000010001011100000001000101110001011101111111
7
00000000000000000000000000000001000000000000000100000001000101110000000000000001000000010001011100000001000101110001011101111111
8
00000000000000000000...

output:

Yes
F
Yes
(a&b)
Yes
(b&(c&a))
Yes
((c&((d&(b|a))|(b&a)))|(d&(b&a)))
Yes
((c&((d&((e&(a|b))|(a&b)))|(e&(a&b))))|(d&(e&(b&a))))
Yes
((e&((d&((a&(f|(c|b)))|((f&(c|b))|(c&b))))|((a&((f&(c|b))|(c&b)))|(f&(c&b)))))|((d&((a&((f&(c|b))|(c&b)))|(f&(c&b))))|(a&(f&(b&c)))))
Yes
((d&((e&((a&((f&(g|(b|c)))|((g&(...

result:

ok 14 lines, tightest: 33 out of 42 (14 test cases)

Test #11:

score: 0
Accepted
time: 38ms
memory: 5712kb

input:

14
1
00
2
0000
3
00000001
4
0000000000000001
5
00000000000000010000000100010111
6
0000000000000000000000000000000100000000000000010000000100010111
7
00000000000000000000000000000001000000000000000100000001000101110000000000000001000000010001011100000001000101110001011101111111
8
00000000000000000000...

output:

Yes
F
Yes
F
Yes
(c&(b&a))
Yes
(b&(c&(a&d)))
Yes
((e&((d&((a&(c|b))|(c&b)))|(a&(c&b))))|(d&(a&(c&b))))
Yes
((d&((f&((e&((c&(a|b))|(a&b)))|(c&(a&b))))|(e&(c&(a&b)))))|(f&(e&(c&(a&b)))))
Yes
((f&((d&((g&((c&(a|(e|b)))|((a&(e|b))|(e&b))))|((c&((a&(b|e))|(b&e)))|(a&(b&e)))))|((g&((c&((a&(b|e))|(b&e)))|(a...

result:

ok 14 lines, tightest: 0 out of 11 (14 test cases)

Test #12:

score: 0
Accepted
time: 69ms
memory: 11916kb

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000...

output:

Yes
((i&((c&((b&((g&((n&((l&((e&(f|(k|(j|(o|(a|(h|(m|d))))))))|((f&(k|(j|(o|(a|(h|(m|d)))))))|((k&(j|(o|(a|(h|(m|d))))))|((j&(o|(a|(h|(m|d)))))|((o&(a|(h|(m|d))))|((a&(m|(h|d)))|((m&(h|d))|(h&d)))))))))|((e&((f&(k|(j|(o|(a|(h|(m|d)))))))|((k&(j|(o|(a|(h|(m|d))))))|((j&(o|(a|(h|(m|d)))))|((o&(a|(h|(m...

result:

ok 1 lines, tightest: 12868 out of 16394 (1 test case)

Test #13:

score: 0
Accepted
time: 88ms
memory: 15616kb

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000100000000000000010000000100010111000000000000000000000000000000000000000...

output:

Yes
((a&((b&((m&((n&((l&((j&(e|(f|(o|(d|(g|(k|(h|(c|i)))))))))|((e&(f|(o|(d|(g|(k|(h|(c|i))))))))|((f&(o|(d|(g|(k|(h|(c|i)))))))|((o&(d|(g|(k|(h|(c|i))))))|((d&(g|(k|(h|(c|i)))))|((g&(k|(h|(c|i))))|((k&(h|(i|c)))|((h&(i|c))|(i&c))))))))))|((j&((e&(f|(o|(d|(g|(k|(h|(c|i))))))))|((f&(o|(d|(g|(k|(h|(c|...

result:

ok 1 lines, tightest: 11438 out of 16394 (1 test case)

Test #14:

score: 0
Accepted
time: 55ms
memory: 9584kb

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

Yes
((g&((a&((o&((e&((d&((c&((n&((k&(l|(b|(m|(h|(f|(j|i)))))))|((l&(b|(m|(h|(f|(j|i))))))|((b&(m|(h|(f|(j|i)))))|((m&(h|(f|(j|i))))|((h&(f|(i|j)))|((f&(i|j))|(i&j))))))))|((k&((l&(b|(m|(h|(f|(j|i))))))|((b&(m|(h|(f|(j|i)))))|((m&(h|(f|(j|i))))|((h&(f|(i|j)))|((f&(i|j))|(i&j)))))))|((l&((b&(m|(h|(f|(...

result:

ok 1 lines, tightest: 11438 out of 16394 (1 test case)

Test #15:

score: 0
Accepted
time: 43ms
memory: 6656kb

input:

1
15
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

Yes
((m&((h&((c&((e&((j&((k&((n&((o&((a&(d|(l|(g|(b|(i|f))))))|((d&(l|(g|(b|(i|f)))))|((l&(g|(b|(i|f))))|((g&(b|(i|f)))|((b&(i|f))|(i&f)))))))|((a&((d&(l|(g|(b|(i|f)))))|((l&(g|(b|(i|f))))|((g&(b|(i|f)))|((b&(i|f))|(i&f))))))|((d&((l&(g|(b|(i|f))))|((g&(b|(i|f)))|((b&(i|f))|(i&f)))))|((l&((g&(b|(i|f...

result:

ok 1 lines, tightest: 8006 out of 16394 (1 test case)

Test #16:

score: 0
Accepted
time: 1958ms
memory: 3584kb

input:

65536
6
0000001101111111000111111111111101111111111111111111111111111111
6
0000000000000000000100110011011100000000000000000001001100111111
6
0101010101110111011101111111111101110111111111111111111111111111
6
0000001100000011000000110001011100011111001111110011111100111111
6
000000010001011100000001...

output:

Yes
((f&(c|(e|(a|(b|d)))))|((c&(e|(b|d)))|((e&(d|(a&b)))|(d&(a|b)))))
Yes
((d&((b&e)|(e&(c&(f|a)))))|(b&(e&(a|c))))
Yes
((f&(b|(a|(d|e))))|((b&(a|(d|e)))|(a|(d&e))))
Yes
((e&((b&(f|(c|(d&a))))|(c&(f|(d&a)))))|((b&(c|(f&(d|a))))|(f&c)))
Yes
((f&((a&(b|c))|(b&(c|d))))|((a&((b&(c|d))|(c&d)))|(b&(c&d)))...

result:

ok 65536 lines, tightest: 36 out of 42 (65536 test cases)

Test #17:

score: -100
Time Limit Exceeded

input:

65536
7
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
7
00000001000100010001000101110111000100010111011101110111011111110001000101110111011101110111111100010001011101110111011111111111
7
000000010001001100000001001101...

output:

Yes
(e&(a&(d&(c&(f&(b&g))))))
Yes
((b&((g&(a|(e|d)))|((a&(c|(e|(f|d))))|((e&(f|d))|(f&d)))))|((g&((a&(e|d))|(e&(d&(c|f)))))|((a&((e&(f|d))|(f&d)))|(c&(e&(f&d))))))
Yes
((f&((g&((a&(b|(d|(c&e))))|((b&(d|(c|e)))|(d&(c|e)))))|((a&(b|(d|(c&e))))|((b&(d|(c|e)))|(d&c)))))|((g&((a&((b&(d|c))|(d&(c&e))))|(b...

result: