Source Code
#include <iostream>
using namespace std ; 
int main() {
  long long n, x, y, z ;
  cin>>n>>x>>y>>z;
  string a,b,s , c;
  cin>>a>>b>>s;
  long long num = n , zero = 0  , one = 0 ; 
  for(int i = 0  ;i<n ; i++)
    {
       if( (a[i]== '0' && b[i]== '1' &&s[i]=='0' ) || (a[i]== '1' && b[i]== '0' && s[i]=='0' )) {x--; c[i]='&';}
      else if (a[i]=='1' && b[i]=='1' && s[i]=='0') {z--; c[i]='^'; }
   
       if(x <0 || z <0  ) 
  {
    cout<<"NO";
    return 0 ; 
    
  }
      
    }
 for(int i = 0 ; i<n ; i++)
   {
       if ((a[i]=='1' &&b[i]=='0' && s[i]=='1') || (a[i]=='0' &&b[i]=='1' && s[i]=='1'))
       {
          if(z> 0 ) 
          {
            c[i]= '^';
            z--;
          }
         else if (y>0) 
         {
           c[i]='|';
           y--;
         }
         else
         {
           cout<<"NO";
           return 0 ; 
         }
       }
    else if (a[i]=='1' && b[i]=='1' && s[i]=='1') 
    {

       if(x> 0 ) 
          {
            c[i]= '&';
            x--;
          }
         else if (y>0) 
         {
           c[i]='|';
           y--;
         }
         else
         {
           cout<<"NO";
           return 0 ; 
         }
    }
   }


  for(int i = 0 ; i<n ; i++)
    {
      if(a[i]=='0'&& b[i]=='0'&&s[i]== '0')
      {
        if(x>0)
        {
          c[i]='&';
          x--;
        }
        else if (y>0)
        {
          c[i]='|';
          y--;
        }
        else if (z>0)
        {
          c[i]='^';
          z--;
        }
      }
    }
  if(x>=0 &&y>=0 && z>= 0 ) 
  {
    cout<<"YES\n";
    for(int i = 0 ; i<n ;i++)
      cout<<c[i];
  }
  else cout<<"NO";
}




///1 0  1 ^ |
//1 0  0 &

//1 1  1 & |
//1 1  0 ^

//0 0 0 & ^ |  
Copy
Binary String Tala_Ibraheem
GNU G++17
2 ms
376 KB
Runtime Error