Source Code
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include<functional>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include<iterator>
#include <stdio.h>
#include <string.h>
#define T int t=0;cin>>t;while(t--)
#define F(i,n) for(int i=0;i<n;i++)
#define fo(i,a)for(auto&i:a)
#define all(a) a.begin(),a.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define ll long long
#define ld long double
#define endl "\n"
#define vl vector<ll>
#define vi vector<int>
#define cost first
#define from second.first
#define to second.second
#define sz(X) X.size()
using namespace std;
const ll mod = 1000000007;
void code();
///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*>> # str main # <<*-*-*-*-*-*-*-*-*-*-*-*-*-*-*///
int main()
{
    code();
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    string x, y, z, ans;
    cin >> x >> y >> z;
    ans=x;
    F(i,n)
    {
        if(x[i]=='0'&&y[i]=='0')
        {
            if(z[i]=='1')return cout<<"NO",0;
            ans[i]='|',b--;
        }
        else if(x[i]=='1'&&y[i]=='1')
        {
            if(z[i]=='1')ans[i]='&',a--;
            else ans[i] ='^',c--;
        }
        else{
            if(z[i]=='0')ans[i]='&',a--;
            else ans[i] ='^',c--;
        }
    }
    for(int i=0;i<n&&a<0;i++)
    {
        if(x[i]=='1'&&y[i]=='1'&&z[i]=='1')ans[i]='|',b--,a++;
    }
    for(int i=0;i<n&&c<0;i++)
    {
        if(x[i]=='0'&&y[i]=='1'&&z[i]=='1')ans[i]='|',b--,c++;
        if(x[i]=='1'&&y[i]=='0'&&z[i]=='1')ans[i]='|',b--,c++;
    }
    for(int i=0;i<n&&b<0;i++)
    {
        if(x[i]=='0'&&y[i]=='0'&&a>0)ans[i]='&',b++,a--;
        else if(x[i]=='0'&&y[i]=='0'&&c>0)ans[i]='^',b++,c--;
    }
    if(a||b||c)cout<<"NO";
    else cout<<"YES\n"<<ans;
}
///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*>> # end main # <<*-*-*-*-*-*-*-*-*-*-*-*-*-*-*///
void code()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(6);
}
Copy
Binary String ABD_ALMABOUD
GNU G++17
7 ms
1.1 MB
Accepted