Source Code
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include<math.h>
#include <string.h>
using namespace std;
typedef vector<int> vi ;
typedef long long ll;
#define all(x) (x).begin() , (x).end()
#define allR(x) (x).rbegin() , (x).rend()
#define pb push_back
const int N = 3e5+5, MX=1e9;

int freq[N][4], num[4];
string a, b, s, ans, op="*&|^";

int main(){ 
    // freopen("input.txt", "r", stdin);
    int n;
    cin >> n>> num[1] >> num[2] >> num[3];
    cin >> a >> b >> s;
    for(int i=0 ; i<n ; i++ ){
        ans+='*';
        if ( s[i] == '1' && a[i]=='0' && b[i] == '0' ){
            puts("NO");
            return 0;
        }
    }
    for(int i=0 ; i<n ; i++ ){
        if( ans[i] != '*' ) continue;
        if ( s[i] =='0' && a[i]==b[i] && a[i] == '1' ){
            if ( !num[3] ){
                puts("NO");
                return 0;
            }
            num[3]--;
            ans[i] = op[3];
        }
        else if ( s[i] =='0' && a[i]!=b[i]  ){
            if ( !num[1] ){
                puts("NO");
                return 0;
            }
            num[1]--;
            ans[i] = op[1];
        }
    }
    for(int i=0 ; i<n ; i++ ){
        if( ans[i] != '*' ) continue;
        if ( a[i]!=b[i] && s[i] == '1' ){
            if ( num[3] ){
                num[3]--;
                ans[i] = op[3];
            }
            else if ( num[2] ){
                num[2]--;
                ans[i] = op[2];
            }
        }
        else if ( a[i]==b[i] && s[i] == '1' && a[i] == '1'){
            if ( num[1] ){
                num[1]--;
                ans[i] = op[1];
            }
            else if (num[2] ){
                num[2]--;
                ans[i] = op[2];
            }
        }
    }
    for(int i=0 ; i<n ; i++ ){
        if( ans[i] != '*' ) continue;
        if ( a[i]==b[i] && a[i]==s[i] && s[i] =='0' ){
            for(int j=1 ; j<=3 ; j++ )
                if( num[j] ){
                    num[j]--;
                    ans[i] = op[j];
                    break;
                }
        }
        if ( ans[i] == '*' ){
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    cout << ans <<"\n";   
}
Copy
Binary String Rand()
GNU G++17
15 ms
1.2 MB
Accepted