Source Code
#include <iostream>
using namespace std;

int main()
{

    int n,a,o,x;
    cin>>n>>a>>o>>x;
    string s1,s2,c;
    cin>>s1>>s2>>c;

    char result[n]={'\0'};

    for(int i=0;i<n;i++){
        if(s1[i]=='0'&&s2[i]=='1'&&c[i]=='0'){
            result[i]='&';
            a--;
            }
        else if(s1[i]=='1'&&s2[i]=='0'&&c[i]=='0'){
            result[i]='&';
            a--;
        }
        else if(s1[i]=='1'&&s2[i]=='1'&&c[i]=='0'){
            result[i]='^';
            x--;
            }
    }

    if(x<0||a<0){
        cout<<"NO"<<endl;
        return 0;
    }

    for(int i=0;i<n;i++){
        if(s1[i]=='1'&&s2[i]=='1'&&c[i]=='1'){
            if(a>0){
                result[i]='&';
                a--;
            }
            else{
                result[i]='|';
                o--;
            }
        }
    }

    if(o<0){
        cout<<"NO"<<endl;
        return 0;
    }

    for(int i=0;i<n;i++){
        if(s1[i]=='0'&&s2[i]=='1'&&c[i]=='1'){
                if(x>0){
                result[i]='^';
                x--;
            }
            else{
                result[i]='|';
                o--;
            }

        }
        else if(s1[i]=='1'&&s2[i]=='0'&&c[i]=='1'){
            if(x>0){
                result[i]='^';
                x--;
            }
            else{
                result[i]='|';
                o--;
            }
        }
    }
    if(o<0){
        cout<<"NO"<<endl;
        return 0;
    }

    for(int i=0;i<n;i++){
        if(s1[i]=='0'&&s2[i]=='0'&&c[i]=='0'){
            if(a>0){
                result[i]='&';
                a--;
            }
            else if(o>0){
                result[i]='|';
                o--;
            }
            else if(x>0){
                result[i]='^';
                x--;
            }
        }
    }


    for(int i=0;i<n;i++){
        if(result[i]=='\0'){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    for(int i=0;i<n;i++){
        cout<<result[i];
    }

    return 0;
}
Copy
Binary String YousefShaheen
GNU G++17
31 ms
1.2 MB
Accepted