Source Code
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int n, x, y, z;
	cin >> n >> x >> y >> z;
	string a, b, s;
	string c = "";
	cin >> a >> b >> s;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == '0' && b[i] == '0' && s[i] == '1')
		{
			cout << "NO\n";
			return 0;
		} 
		else if (a[i] != b[i] && s[i] == '0')
		{
			x--;
			c += '&';
		}
		else if (a[i] == '1' && b[i] == '1' && s[i] == '0')
		{
			z--;
			c += '^';
		}
		else if (a[i] != b[i] && s[i] == '1')
		{
			if (y > 0) {
				y--;
				c += '|';
			}
			else if (z > 0) {
				z--;
				c += '^';
			}
			else {
				cout << "NO\n";
				return 0;
			}
		}
		else if (a[i] == '1' && b[i] == '1' && s[i] == '1')
		{
			if (x > 0) {
				x--;
				c += '&';
			}
			else if (y > 0) {
				y--;
				c += '|';
			}
			else {
				cout << "NO\n";
				return 0;
			}
		}
		else if (a[i] == '0' && b[i] == '0' && s[i] == '0')
		{
			if (y > 0) {
				y--;
				c += '|';
			}
			else if (x > 0) {
				x--;
				c += '&';
			}
			else if (z > 0) {
				z--;
				c += '^';
			}
			else {
				cout << "NO\n";
				return 0;
			}
		}
		if (x < 0 || y < 0 || z < 0)
		{
			cout << "NO\n";
			return 0;
		}
		//cout << "and: " << x << " OR: " << y << " XOR: " << z << " C: " << c << endl;
	}
	cout << "YES\n";
	cout << c << endl;
}
Copy
Binary String Heromnxpw0
GNU G++17
3 ms
820 KB
Wrong Answer