Source Code
#include<bits/stdc++.h>
#include "cmake-build-debug/Car.h"
using namespace std;

void fast() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
int n,x,y,z;
string a,b,c ;
vector<char> solve(int n, int x , int y , int z , string a , string b, string c  )
{
    vector<char> ans(n) ;
    for (int i=0 ;i<n ;i++)
    {
        if (a[i] == '1' && b[i]=='0' && c[i] =='0' && x>0 )
        {
            x--;
            ans [i] =  '&' ;
        }
        else if (a[i] == '1' && b[i]=='0' && c[i] =='0' && x<=0 )
        {
            ans.clear() ;
            return ans ;
        }
        else if (a[i] == '0' && b[i] == '1' && c[i]=='0' && x>0)
        {
            x--;
            ans [i] =  '&' ;
        }
        else if (a[i] == '0' && b[i] == '1' && c[i]=='0' && x<=0)
        {
            ans.clear() ;
            return ans ;
        }
        else if (a[i]=='1'&&b[i]=='1'&&c[i]=='0'&&z>0)
        {
            z--;
            ans [i] = '^' ;
        }
        else if (a[i]=='1'&&b[i]=='1'&&c[i]=='0'&&z<=0)
        {
            ans.clear() ;
            return ans ;
        }
        else if (a[i]=='0'&&b[i]=='0'&&c[i]=='1')
        {
            ans.clear() ;
            return ans ;
        }
    }
    for (int i=0 ;i<n ;i++)
    {
        if (a[i]=='1'&&b[i]=='1'&&c[i]=='1' && x>0 )
        {
            x--;
            ans [i] =  '&' ;
        }
        else if (a[i]=='1'&&b[i]=='1'&&c[i]=='1' && y>0 )
        {
            y--;
            ans [i] = '|' ;
        }
        else if (a[i]=='1'&&b[i]=='1'&&c[i]=='1' && x<=0 && y<=0 )
        {
            ans.clear() ;
            return ans ;
        }
        else if (a[i] == '0' && b[i] == '1' && c[i] == '1' && z>0)
        {
            z--;
            ans [i] =  '^' ;
        }
        else  if (a[i] == '0' && b[i] == '1' && c[i] == '1' && y>0)
        {
            y--;
            ans [i] = '|' ;
        }
        else  if (a[i] == '0' && b[i] == '1' && c[i] == '1' && z<=0 && y<=0)
        {
            ans.clear()  ;
            return ans ;
        }
        else if (a[i] == '1' && b[i]=='0' && c[i] =='1' && z>0 )
        {
            z--;
            ans[i] = '^' ;
        }
        else if (a[i] == '1' && b[i]=='0' && c[i] =='1' && y>0 )
        {
            y--;
            ans [i] =  '|' ;
        }
        else if (a[i] == '1' && b[i]=='0' && c[i] =='1' && y<=0 && z<=0 )
        {
            ans.clear() ;
            return ans ;
        }
    }
    for (int i=0 ;i<n;i++)
    {
        if (a[i] == '0' && b[i] == '0' && c[i] =='0' && x>0)
        {
            x--;
            ans [i] = '&' ;
        }
        else if (a[i] == '0' && b[i] == '0' && c[i] =='0' && z>0)
        {
            z--;
            ans [i] = '^' ;
        }
        else if (a[i] == '0' && b[i] == '0' && c[i] =='0' && y>0)
        {
            y--;
            ans [i] =  '|' ;
        }
        else if (a[i] == '0' && b[i] == '0' && c[i] =='0' && x<=0 && y<=0 && z<=0)
        {
            ans.clear() ;
            return ans ;
        }
    }
    if (x != 0 || y !=0 || z != 0 )ans.clear() ;
    return ans ;
}
int main() {
    fast() ;
    cin>>n>>x>>y>>z>>a>>b>>c  ;
    vector<char>ans = solve(n,x,y,z,a,b,c) ;
    if (ans.size() == 0 )cout << "NO" ;
    else {
        cout <<"YES\n"  ;
        for (int i=0 ;i<n;i++)
            cout << ans[i] ;
    }
    return  0 ;
}
Copy
Binary String Zidaan
GNU G++17
0 ms
0 KB
Compilation Error