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="*&|^";

void check( int x ){
    for(int i=0 ; i<s.size() ; i++ ){
        if ( ans[i] != '*' ) continue;
        int flag=0, cnt=0;
        for(int j=1 ; j<=3 ; j++ ){
            if ( freq[i][j]>0 && num[j] ){
                flag=j;
                cnt++;
            }
        }
        if ( cnt && cnt <= x ){
            ans[i] = op[flag]; 
            freq[i][flag]--;
            num[flag]--;
        }
    }
}
int main(){ 
    // freopen("input.txt", "r", stdin);
    int n, x, y , z;
    cin >> n>> num[1] >> num[2] >> num[3];
    cin >> a >> b >> s;
    for(int i=0 ; i<n ; i++ ){
        ans+='*';
        if ( a[i] == b[i] && s[i] != a[i] )
            freq[i][3]+= (a[i]-'0');
        if ( a[i] == b[i] && s[i] == a[i] ){
            freq[i][2]++; // or
            freq[i][1]++; //and
            freq[i][3]+=!(a[i]-'0'); // xor
        }
        if ( a[i] != b[i] ){
            if ( s[i] == '0' )
                freq[i][1]++;
            else{
                freq[i][2]++;
                freq[i][3]++;
            }
        }
    }
    // cout <<"& | ^\n";
    // for(int i=0 ; i<n ; i++ ){
    //     for(int j=1 ; j<=3  ; j++ )
    //         cout << freq[i][j] <<" ";
    //     puts("");
    // }
    // cout <<"------\n";
    for(int i=0 ; i<3 ; i++ )
        check(i+1); 
    for(int i=0 ; i<n ; i++ )
        if ( ans[i] == '*' ){
            puts("NO");
            return 0;
        }
    puts("YES");
    cout << ans ;
    
}
Copy
Binary String Rand()
GNU G++17
1 ms
196 KB
Wrong Answer