Source Code
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
/* #pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
typedef long long ll;
const ll MAXK = 3e3 + 5;
const ll MOD = 1e9 + 7;
const ll MODH = 1e9 + 9;
const int MAXLG = 20;
const long double PI = acos(-1);
const ll p = 41;
const long double EPS = 1e-4;
#define x first
#define y second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll rand(ll a, ll b) {ll c = rng(); return a+((ll)abs(c))%(b-a+1);}
ll binpowmod(ll a, ll b, ll m) {a %= m;ll res = 1;while (b > 0) {if (b & 1){res = res * a % m;}a = a * a % m;b >>= 1;
 
}return res;}
//typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,  //less_equal
  //           tree_order_statistics_node_update> oset;
const int MAXN = 1e6 + 5;
bool bad = 0;
int n,x,y,z;
void do_special(string &a,string &b,string &s,vector<char> &ans)
{
  for(int i = 0 ; i < n ; i++)
  {
    int aa = a[i] - '0';
    int bb = b[i] - '0';
    int ss = s[i] - '0';

    if(aa != bb and ss == 0)
      {
          if(!x)
             {
              bad = 1;
              return;
             }
          else
          {
            --x;
            ans[i] = '&';
          }
      }
      else if(aa == bb)
      {
         if(ss == 0 and aa == 1)
         {
           if(z)
          {
            --z;
            ans[i] = '^';
          }
          else
          {
            bad = 1;
            return;
          }
         }
      }
  }
}

int main()
{

ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);


int t = 1;
while(t--)
{
 bad = 0;
  cin >> n >> x >> y >> z;
  string a,b,s;
  cin >> a >> b >> s;
  vector<char> ans(n,'#');
  do_special(a,b,s,ans);
  for(int i = 0 ; i < n ; i++)
  {
    if(ans[i] != '#')
       continue;
    int aa = a[i] - '0';
    int bb = b[i] - '0';
    int ss = s[i] - '0';
     

   if(aa != bb and ss == 1)
   {
    if(y) // or
    {
      --y;
      ans[i] = '|';
    }
    else if(z) //xor
    {
      --z;
      ans[i] = '^';
    }
    else 
    {
      bad = 1;
      break;
    }
   }
   else if(aa == bb and aa == 1 and ss == 1)
   {
     if(y) // or
    {
      --y;
      ans[i] = '|';
    }
    else if(x) //and
    {
      --x;
      ans[i] = '&';
    }
    else 
    {
      bad = 1;
      break;
    }
   }
   else if(aa == bb and aa == 0 and ss == 0)
   {
       if(y) // or
    {
      --y;
      ans[i] = '|';
    }
    else if(x) //and
    {
      --x;
      ans[i] = '&';
    }
    else if(z)
    {
       --z;
       ans[i] = '^';
    }
    else 
    {
      bad = 1;
      break;
    }
   }


  }

  if(!bad)
  {
    cout << "YES\n";
    for(auto &k : ans)
       cout << k;
     cout << '\n';
  }
  else
     cout << "NO";

}



}
Copy
Binary String DoeJohn
GNU G++17
2 ms
456 KB
Wrong Answer