Source Code
#include <iostream>
#include <iomanip>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <set>
#include <cstdio>
#include <string>
#include <stack>
#include <map>
#include <sstream>

#define ll long long
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()
using namespace std;
void AIA()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void file()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
const int OO = 1e9 + 7;
const long double PI = acos(-1);
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dx4[] = {0, 1, 0, -1};
int dy[] = {1, -1, 0, 0, 1, -1, -1, 1}, dy4[] = {1, 0, -1, 0};
int main()
{
    // Verify Your thought before Coding.
    AIA();
    file();
    int n, andd, orr, xorr;
    cin >> n >> andd >> orr >> xorr;
    string a, b, c;
    char res[n];
    cin >> a >> b >> c;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == '0' && b[i] == '0' && c[i] == '1')
        {
            cout << "NO";
            return 0;
        }
        else if (a[i] != b[i] && c[i] == '0')
        {
            res[i] = '&';
            andd--;
            if (andd < 0)
            {
                cout << "NO";
                return 0;
            }
        }
        else if (a[i] == '1' && b[i] == '1' && c[i] == '0')
        {
            xorr--;
            res[i] = '^';
            if (xorr < 0)
            {
                cout << "NO";
                return 0;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (a[i] == '0' && b[i] == '1' && c[i] == '1')
        {
            // xor | or
            if (xorr > 0)
            {
                res[i] = '^';
                xorr--;
            }
            else if (orr > 0)
            {
                res[i] = '|';
                orr--;
            }
            else
            {
                cout << "NO";
                return 0;
            }
        }
        else if (a[i] == '1' && b[i] == '0' && c[i] == '1')
        {
            // xor | or
            if (xorr > 0)
            {
                res[i] = '^';
                xorr--;
            }
            else if (orr > 0)
            {
                res[i] = '|';
                orr--;
            }
            else
            {
                cout << "NO";
                return 0;
            }
        }

        else if (a[i] == '1' && b[i] == '1' && c[i] == '1')
        {
            // and | or
            if (andd > 0)
            {
                andd--;
                res[i] = '&';
            }
            else if (orr > 0)
            {
                orr--;
                res[i] = '|';
            }
            else
            {
                cout << "NO";
                return 0;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (a[i] == '0' && b[i] == '0' && c[i] == '0')
        {
            if (andd > 0)
            {
                res[i] = '&';
                andd--;
            }
            else if (orr > 0)
            {
                res[i] = '|';
                orr--;
            }
            else if (xorr > 0)
            {
                res[i] = '^';
                xorr--;
            }
            else
            {
                cout << "NO";
                return 0;
            }
        }
    }
    cout << "YES\n";
    for (auto it : res)
        cout << it;
}
Copy
Binary String kareemabdelrhmane
GNU G++17
16 ms
1.2 MB
Accepted