Source Code
#include <bits/stdc++.h>
using namespace std;
#define   IOS   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#define   mp make_pair
#define   pb push_back
#define   ll long long
#define   debug(x)  cout << '[' << #x << " is: " << x << "] " << endl;
#define   debugg(x,y)  cout << '[' << #x << " is: " << x << "] " << " " << '[' << #y << " is: " << y << "] ";
#define   rsor(v)   sort(v.rbegin() , v.rend());
#define   rev(v)    reverse(v.begin() , v.end());
#define   sz(x)     (int)(x).size()
#define   all(x)    x.begin(), x.end()
#define  _cout(v)  for(auto f : v ) cout << f << " " ;
#define  _cin(v)   for(auto &it : v)cin >> it ;
#define  _for(v)   for(int i=0;i<(v);i++)
#define   PFD(n) cout.precision(n)<<fixed
#define gc getchar_unlocked
#define  fs first
#define  sc second
const long double PI=3.14159265359;
#define  int long long
#define  vi vector<int>
void out() {
   cout << "NO";
   return;
}
void setIO(string name = "") {if(sz(name)){freopen((name+".in").c_str(), "r", stdin);
                                            freopen((name+".out").c_str(), "w", stdout);}}
int calc(int n){
   return n*(n+1)/2;
}
void solve(){
   // Think twice code once
   int n,x,y,z;
   cin >> n >> x >> y >> z;
   string a,b,c;
   cin >> a >> b >> c;
   string s = "&|^";
   string ans = "";
   map<char,int>mp={{'&',x},{'|',y},{'^',z}};
   int i=0;
   while(true && i<n){
      if (a[i]==b[i]){
         if ( a[i]==c[i]){
            int to = 1;
            if (mp['&']>mp['|'])to=0;
            char add = s[to];
            if (mp[add])ans+=add;
            mp[add]--;
         }
         else {
            ans += '^';
         }
      }
      else {
         int to = 2;
         if (mp['|']>mp['z'])to=1;
         char add = s[to];
         if (mp[add])ans+=add;
         mp[add]--;
      }
      i++;
   }
   if (sz(ans)!=n){
      cout << "NO";
      return;
   }
   cout << "YES\n";
   cout << ans << '\n';
}
int32_t main() {
    IOS;
    int _=1;
    //cin>>_;
    for(int tc=1;tc<=_;tc++){
        // cout << "ase #" << tc << ": ";
        solve();
        //cout << (1^1);
        //cout << (1|0);
        //cout << (0&0);
    }

}
Copy
Binary String Anas_AbuAmar
GNU G++17
1 ms
192 KB
Wrong Answer