Source Code
#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
bool visa[(int)1e6] ;
int x[1000000][3] ;
char res[1000000];
int main(){
   ios_base::sync_with_stdio(0);cin.tie(0);
    int n , t , y , z ;
    string a , b , c;
    cin >> n >> t >> y >> z;
    cin >> a >> b >> c;
    for ( int i = 0 ; i < n ; i++ ) {
    	a[i]-='0';
    	b[i]-='0';
    	c[i]-='0';
    	if ( ((int)a[i]&&(int)b[i]) == (int)c[i] ) x[i][0] = 1;
    	if ( ((int)a[i]||(int)b[i]) == (int)c[i] ) x[i][1] = 1;
    	if ( ((int)a[i]^(int)b[i]) == (int)c[i] ) x[i][2] = 1;
    	res[i] = 't' ;
    }
    for ( int i = 0 ; i < n ; i++ ) {
    	if ( x[i][0]+x[i][1]+x[i][2] == 1 ) {
    		if(x[i][0]){
    			res[i] = '&';
    			t--;
    		}
    		if(x[i][1]){
    			res[i] = '|';
    			y--;
    		}
    		if(x[i][2]){
    			res[i] = '^';
    			z--;
    		}
    	}
    }
    if (t<0||y<0||z<0) cout << "NO";
    else {
    	cout << "YES\n";
    	for ( int i = 0 ; i < n ; i++ ) {
    		if ( res[i] != 't' ) cout << res[i]; 
    		else {
    			for ( int j = 0 ; j < 3 ; j++) {
    			    //if ( i == 3 ) cout << t << ")";
    				if ( x[i][j] == 1 ) {
    				    //if ( i == 3 ) cout << t << ")";
    					if(j==0&&t>0) {
    						t--;
    						cout << '&';
    						break;
    					}
    					else if (j==1&&y>0) {
    						y--;
    						cout << '|';
    						break;
    					}
    					else if (j==2&&z>0) {
    						z--;
    						cout << '^';
    						break;
    					}
    					//if ( i == 3 ) cout << t << ")";
    				}
    			}
    		}
    		//cout << t << y << z << endl;
    	}
    }
   return 0;
}
Copy
Binary String SAAD
GNU G++17
1 ms
368 KB
Wrong Answer