Source Code
#include<bits/stdc++.h>
#include <unordered_map>
#include<unordered_set>
// Header files, namespaces,
// macros as defined above
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
#define _USE_MATH_DEFINES
# define M_PI           3.14159265358979323846  /* pi */
#define ll long long
#define ull unsigned long long
#define ld long double
#define vbe(v) ((v).begin()), ((v).end())
#define sz(v)     ((int)((v).size()))
#define prec(x)    cout<< fixed<< setprecision(x)
#define clr(v, d)   memset(v, d, sizeof(v))
#define rep(i, v)   for(int i=0;i<sz(v);++i)
#define lp(i, n)    for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)  for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)  for(int i=(j);i>=(int)(n);--i)
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cin.tie(0);
#define INFLL 1e18
#define INF 1e9
#define MOD 1000000007
#define MOD1 998244353
#define MAXN 200010
#define EPS 1e-6

ll GCD(ll a, ll b) { return (a) ? GCD(b % a, a) : b; }

ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

ll fastpow(ll b, ll p) {
    if (!p) return 1;
    ll ret = fastpow(b, p >> 1);
    ret *= ret;
    if (p & 1) ret *= b;
    return ret;
}

void solve(int tst) {
    int n, andd, orr, xorr;
    cin >> n >> andd >> orr >> xorr;
    string a, b, c;
    cin >> a >> b >> c;
    string ans = c;
    deque<int> xorIdx, orIdx, andIdx;
    //        and  or xor
    //0 0       0  0  0
    //0 1       0  1  1
    //1 1       1  1  0
    vector<int> maZZ;
    vector<int> maZO;
    vector<int> maOO;
    lp(i, n) {
        int aa = a[i] - '0';
        int bb = b[i] - '0';
        int cc = c[i] - '0';
        if (aa > bb)swap(aa, bb);
        if (aa == 0 && bb == 0) {
            if (cc != 0) {
                cout << "NO";
                return;
            }
            maZZ.push_back(i);
        } else if (aa == 0 && bb) {
            if (cc) {
                if (andd) {
                    andd--;
                    ans[i] = '&';
                } else {
                    cout << "NO";
                    return;
                }
            } else {
                if (!cc) {
                    if (xorr) {
                        xorr--;
                        ans[i] = '^';
                    } else {
                        cout << "NO";
                        return;
                    }
                } else
                    maZO.push_back(i);
            }
        } else if (aa && bb) {
            maOO.push_back(i);
        }
    }

    //        and  or xor
    //0 0       0  0  0
    //0 1          1  1
    //1 1       1  1
    vector<int>doneAnd,doneXor,doneOr;
    for (auto i:maZZ) {
        if (andd) {
            andd--;
            ans[i] = '&';
            doneAnd.push_back(i);
        } else if (orr) {
            orr--;
            ans[i] = '|';
            doneOr.push_back(i);
        } else if (xorr) {
            xorr--;
            ans[i] = '^';
            doneXor.push_back(i);
        } else {
            cout << "NO";
            return;
        }
    }
    //        and  or xor
    //0 0       0  0  0
    //0 1          1  1
    //1 1       1  1
    for (auto i:maZO) {
        if (orr) {
            orr--;
            ans[i] = '|';
        } else if (xorr) {
            xorr--;
            ans[i] = '^';
        } else {

            cout << "NO";
            return;
        }
    }
    for (auto i:maOO) {
        if (orr) {
            orr--;
            ans[i] = '|';
        } else if (andd) {
            andd--;
            ans[i] = '&';
        } else {

            cout << "NO";
            return;
        }
    }
    cout << "YES\n";
    cout << ans;

    /*
     * 3 1 1 1
111
001
101
     ^&|
     */
}

int main() {
    FASTIO;
    //freopen("circles.in", "r", stdin);
    int t = 1;
    //cin >> t;
    lp(i, t) {
        solve(i + 1);
        cout << "\n";
    }
}
Copy
Binary String gaserashraf
GNU G++17
2 ms
244 KB
Wrong Answer