Source Code
#include<bits/stdc++.h>
#define cin(vec) for(auto& i : vec) cin >> i
#define cout(vec) for(auto& i : vec) cout << i 
#define ll long long
#define author_mohamed cin.tie(0)->sync_with_stdio(0);cin.exceptions(cin.failbit);
#define ss short
#define umset unordered_multiset
#define uset unordered_set
#define fx(b)  fixed << setprecision(b)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define vis vector<string>
#define t   int t;cin >> t;while(t--)
#define vi vector
#define st string
#define mod  1000000007
#define mp   make_pair
using namespace std;
ll gcd(ll a, ll b) {if (a < b)swap(a, b);while (a != 0 && b != 0) {ll r = a % b;a = b;b = r;}return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
unsigned ll nCr(int n, int r) {if (r > n)return 0;r = max(r, n - r); unsigned ll ans = 1, div = 1, i = r + 1;while (i <= n) {ans *= i;i++;ans /= div;div++;}return ans;}
 unsigned ll npr(int n,int r){if(r>n)return 0;unsigned ll a=1,i=n-r+1; while(i<=n){a*=i;i++;}return a;}
int xc[4] = {-1, 1, 0, 0};
int yc[4] = {0, 0, -1, 1};
 

void solve(){
   vi<pair<int,char>>w(3);
   int n,x,y,z;cin>>n;
   for(int i=0;i<3;i++){
      cin>>w[i].first;
      if(i==0)w[i].second='x';
      else if(i==1){
         w[i].second='y';
      }
      else w[i].second='z';
   }
   sort(rall(w));
   st a,b,s;
   cin>>a>>b>>s;
   st q="";
   for(int i=0;i<n;i++){
      int a1=a[i]-'0',b1=b[i]-'0',s1=s[i]-'0';
      for(int j=0;j<3;j++){
         if(w[j].second=='x'&&(a1&b1)==s1){
            w[j].first--;q+='&';break;
         } 
         else if(w[j].second=='y'&&(a1|b1)==s1){
            w[j].first--;
            q+='|';break;
         }
         else if(w[j].second=='z'&&(a1^b1)==s1){
            w[j].first--;
            q+='^';break;
         }
      }
      sort(rall(w));
   }
   
   if(!w[1].first&&!w[0].first&&!w[2].first){
      cout<<"YES\n";
      cout<<q;
   }
   else cout<<"NO";
}
int main()
{
author_mohamed
//freopen("in.txt", "r", stdin);
 //freopen("out.txt", "w", stdout);

   solve();

 return 0;
}
Copy
Binary String mohamed
GNU G++17
1 ms
244 KB
Wrong Answer