Source Code
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define pb push_back
#define pp pop_back
#define f first
#define s second
typedef long long ll;
typedef long double ld;
ld pi=acos(-1);
ll mod=1e9+7;
void fast()
{
	cin.sync_with_stdio(0) ;
		cin.tie(0) ;
		cout.tie(0);
}
bool cmp(pair<int,int>a,pair<int,int>b)
{
	if(a.first==b.first)
		return b.second>a.second;
	return a.first<b.first;
}
long long gcd(long long a,long long b)
{
	if(a==0)
		return b;
	return gcd(b%a,a);
}
long long fp(ll b, ll p)
{
    ll ans = 1;
    while (p)
    {
        if (p % 2)
        {
            ans = (ans * b)%mod;
        }
        b = (b * b)%mod;
        p /= 2;
    }
    return ans%mod;

}
bool isp(long long n)
{
	if(n==1)
		return false;
	if(n==2||n==3)
		return true;
	if(n%2==0||n%3==0)
		return false;
	for(long long i=5;i*i<=n;i+=2)
		if(n%i==0)
			return false;
	return true;
}
long long fc(long long n)
{
	if(n==0)
		return 1;
	long long s=1;
	for(int i=1;i<=n;i++)
		s=s*i;
	return s;
}
ll lcm(ll a,ll b)
{
	ll m=gcd(a,b);
	m=a/m*b;
	return m;
}
#define MAX 10000001
ll primes[MAX] ;
bool sieve[MAX] ;
int l;
void genPrimes()
{
    primes[l++] = 2 ;
    long long i,j ;
    for(j=4;j<MAX;j+=2)               sieve[j] = true ;
    for(i=3;i<MAX;i+=2)
    {
        if(sieve[i]==false)
        {
            primes[l++] = i ;
            for(j=i*i;j<MAX;j+=i)   sieve[j] = true ;
        }
    }
}
void Nn(ll n)
{
	map<int,int>mp;
	int od=0,ev=0;
    ll tmp = sqrt(n),i ;
    ll j = 0 ;
    ll p[1000];
    memset(p,0,sizeof(p));
    for(i=0;primes[i]<=tmp;i++)
        if(n % primes[i] == 0)
        {
            int cnt =  0 ;
            while(n % primes[i] == 0)
            {
                cnt ++ ;
                //cout<<"    "<<primes[i]<<"\n";
                n /=primes[i] ;
            }
            if(cnt%2)
            	od++;
            else
            	ev++;
            p[j++]=primes[i] ;
            mp[primes[i]]=cnt;
            tmp = sqrt(n) ;
        }
    if(n>1) {
    	p[j++]=n;
    	od++;
    //	cout<<"    "<<n<<"\n";
    	mp[n]++;
    }
    sort(p,p+j);
    for(int i=0;i<j;i++)
    	cout<<p[i]<<'^'<<mp[p[i]]<<" ";
   // sort(p,p+j);

}
/*ll c=1e9+7;
ll modd(ll a,ll b)
{
	ll rs=0;
	a=a%c;
	while(b)
	{
		if(b%2)
			rs=(rs+a)%c;
		a=(2*a)%c;
		b/=2;
	}
	return rs;
}*/
const int N = 1000001;
ll factorialNumInverse[N + 1];
ll naturalNumInverse[N + 1];
ll fact[N + 1];
 void InverseofNumber(ll p)
{
    naturalNumInverse[0] = naturalNumInverse[1] = 1;
    for (int i = 2; i <= N; i++)
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
}
void InverseofFactorial(ll p)
{
    factorialNumInverse[0] = factorialNumInverse[1] = 1;

    for (int i = 2; i <= N; i++)
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
}
 void factorial(ll p)
{
    fact[0] = 1;
     for (int i = 1; i <= N; i++) {
        fact[i] = (fact[i - 1] * i) % p;
    }
}
 ll B(ll N, ll R, ll p)
{
    ll ans = ((fact[N] * factorialNumInverse[R])
              % p * factorialNumInverse[N - R])% p;
    return ans;
}
 ll k;
 vector<ll>c;
 void sol(ll p)
 {
	    for(int i=0;i<=1e5;i++)
	    {
	    	ll sm=0;
	    	for(int j=0;j<=i/k;j++)
	    		sm=(sm+B(i-j*(k-1),j,p))%p;
	    	if(c.empty())
	    		c.pb(sm);
	    	else
	    		c.pb((sm+c.back())%p);

	    }
 }
int main() {
    fast();
	int tt=1;
	//cin>>tt;
	for(int ts=1;ts<=tt;ts++)
	{
		int n,x,y,z;
		cin>>n>>x>>y>>z;
		string s1,s2,s;
		map<int,char>ss;
		cin>>s1>>s2>>s;
		bool h=1;
		for(int i=0;i<n;i++)
		{
			if(s1[i]!=s2[i]&&s[i]=='0')
				x--,ss[i]='&';
			if(s1[i]=='1'&&s2[i]=='1'&&s[i]=='0')
				z--,ss[i]='^';
		}
		int o=0,ze=0;
		for(int i=0;i<n;i++)
		{
			if(s1[i]!=s2[i]&&s[i]=='1')
			{
				if(z>=1)
					ss[i]='^',z--;
				else if(y>=1)
					ss[i]='|',y--;
				else
					h=0;
			}
			else if(s1[i]=='0'&&s2[i]=='0'&&s[i]=='1')
				h=0;
		}
		for(int i=0;i<n;i++)
		{
			if(s1[i]==s2[i]&&s1[i]==s[i]&&s[i]=='0')
			{
				if(z>0)
					ss[i]='^',z--;
				else if(x>0)
					ss[i]='&',x--;
				else if(y>0)
					ss[i]='|',y--;
				else
					h=0;
			}
			else if(s1[i]==s2[i]&&s1[i]==s[i]&&s[i]=='1')
			{
				if(x>0)
					ss[i]='&',x--;
				else if(y>0)
					ss[i]='|',y--;
				else
					h=0;
			}
		}
		if(h==0||x!=0||y!=0||z!=0)
			cout<<"NO\n";
		else
		{
			cout<<"YES\n";
			for(int i=0;i<n;i++)
				cout<<ss[i];
			cout<<"\n";
		}
	}
	return 0;
}
Copy
Binary String sameh58
GNU G++17
110 ms
8.9 MB
Accepted