Source Code
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, x, y, z;
	cin >> n >> x >> y >> z;
	string a, b, c;
	cin >> a >> b >> c;
	vector<pair<int, int>> v;
	v.push_back({x, 1});
	v.push_back({y, 2});
	v.push_back({z, 3});
	string ans;
	bool okk = 1;
	for (int i = 0; i < n; i++)
	{
		sort(v.begin(), v.end());
		bool ok[4] = {1, 0, 0, 0};
		if (c[i] == '0' && (a[i] == '0' || b[i] == '0'))
			ok[1] = 1;
		if (c[i] == '1' && a[i] == b[i] && a[i] == '1')
			ok[1] = 1;
		if (c[i] == '0' && a[i] == b[i] && a[i] == '0')
			ok[2] = 1;
		if (c[i] == '1' && (a[i] == '1' || b[i] == '1'))
			ok[2] = 1;
		if (c[i] == '0' && a[i] == b[i])
			ok[3] = 1;
		if (c[i] == '1' && a[i] != b[i])
			ok[3] = 1;

		int u = 2;
		while (u != -1)
		{
			if (v[u].F > 0 && ok[v[u].S] == 1)
				break;
			u--;
		}
		if (u == -1)
		{
			okk = 0;
			break;
		}

		int g = v[u].S;
		v[u].F--;
		if (g == 1)
			ans += "&";
		if (g == 2)
			ans += "|";
		if (g == 3)
			ans += "^";
	}

	if (okk)
	{
		cout << "YES\n";
		cout << ans;
	}
	else
		cout << "NO";

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