Advertisement
El_GEMMY

a

Apr 17th, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.09 KB | None | 0 0
  1. // Those who cannot remember the past are
  2. // condemned to repeat it (use DP -_-)
  3. // - George Santayana
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8.  
  9. using namespace std;
  10. using namespace __gnu_pbds;
  11.  
  12. #define all(v) v.begin(),v.end()
  13. #define rall(v) v.rbegin(),v.rend()
  14. #define ll long long
  15. #define ull unsigned long long
  16. #define MOD 1000000007
  17. #define PI 3.14159265
  18. #define ceil(a, b) ((a / b) + (a % b ? 1 : 0))
  19. #define imin INT_MIN
  20. #define imax INT_MAX
  21. #define llmax LLONG_MAX
  22. #define llmin LLONG_MIN
  23. #define inf 2000000000
  24. #define nl '\n'
  25. #define ppcnt __builtin_popcount
  26. #define ppcntll __builtin_popcountll
  27. #define clz __builtin_clz
  28. #define clzll __builtin_clzll
  29. #define ctz __builtin_ctz
  30. #define ctzll __builtin_ctzll
  31. #define modulo(a, b, mod) ((((a) % mod) * ((b) % mod)) % mod)
  32. #define cnte(v, x) count(all(v), (x))
  33. #define mine(v) min_element(all(v))
  34. #define maxe(v) max_element(all(v))
  35. #define debug(x) cout << "x: " << x << nl;
  36. #define debug2(x, y) cout << "x: " << x << " y: " << y << nl;
  37. #define ordered_set tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>
  38. #define ordered_map tree<int, int, less<>, rb_tree_tag, tree_order_statistics_node_update>
  39.  
  40. //vector<int> dx = {0, 0, 1, -1, 1, 1, -1, -1}, dy = {1, -1, 0, 0, 1, -1, 1, -1};
  41. //vector<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};
  42.  
  43. template<typename T = int> istream& operator>>(istream& in, vector<pair<int, int>>& v){
  44.     for (auto& [x, y] : v) in >> x >> y;
  45.     return in;
  46. }
  47.  
  48. template<typename T = int> istream& operator>>(istream& in, vector<T>& v){
  49.     for (T& i : v) in >> i;
  50.     return in;
  51. }
  52.  
  53. template<typename T = int> ostream& operator<<(ostream& out, const vector<T>& v){
  54.     for (const T& x : v)
  55.         out << x << ' ';
  56.     return out;
  57. }
  58.  
  59. template<typename T = pair<int, int>> ostream& operator << (ostream& out, const vector<pair<int, int>>& v){
  60.     for(auto& [x, y] : v){
  61.         out << x << ' ' << y << nl;
  62.     }
  63.     return out;
  64. }
  65.  
  66. void Start_Crushing() {
  67.     ios_base::sync_with_stdio(false);
  68.     cin.tie(nullptr);
  69.     cout.tie(nullptr);
  70. #ifndef ONLINE_JUDGE
  71.     freopen("input.txt", "r", stdin);
  72.     freopen("output.txt", "w", stdout);
  73. #endif
  74. }
  75.  
  76. void solve(){
  77.     int n, x, y, z; cin >> n >> x >> y >> z;
  78.     string a, b, c, s; cin >> a >> b >> s;
  79.  
  80.     for(int i = 0; i < n; i++){
  81.         if(a[i] == b[i] and a[i] == '0' and s[i] == '1'){
  82.             return void(cout << "NO");
  83.         }else if(a[i] != b[i] and s[i] == '0'){
  84.             if(not x)
  85.                 goto no;
  86.  
  87.             x--;
  88.             c += '&';
  89.         }else if(a[i] == b[i] and a[i] == '1' and s[i] == '0'){
  90.             if(not z)
  91.                 goto no;
  92.  
  93.             z--;
  94.             c += '^';
  95.         }else if(a[i] == b[i] and a[i] == '1' and s[i] == '1'){
  96.             if(not(x or y))
  97.                 goto no;
  98.  
  99.             if(x){
  100.                 c += '&';
  101.                 x--;
  102.             }else{
  103.                 c += '|';
  104.                 y--;
  105.             }
  106.         }else if(a[i] != b[i] and s[i] == '1'){
  107.             if(not(z or y))
  108.                 goto no;
  109.  
  110.             if(z){
  111.                 c += '^';
  112.                 z--;
  113.             }else{
  114.                 c += '|';
  115.                 y--;
  116.             }
  117.         }else if(a[i] == b[i] and a[i] == '0' and s[i] == '0'){
  118.             if(not(x or y or z))
  119.                 goto no;
  120.  
  121.             if(x){
  122.                 c += '&';
  123.                 x--;
  124.             }else if(z){
  125.                 c += '^';
  126.                 z--;
  127.             }else{
  128.                 c += '|';
  129.                 y--;
  130.             }
  131.         }
  132.     }
  133.  
  134.     return void(cout << "YES" << nl << c);
  135.     no:
  136.     cout << "NO";
  137. }
  138.  
  139. int main(){
  140.     Start_Crushing();
  141.  
  142.     int t = 1;
  143. //    /*Multiple test cases?*/ cin >> t;
  144.     while (t--) {
  145.         solve();
  146.         if(!t)
  147.             break;
  148.         cout << nl;
  149.     }
  150.  
  151. //    for(int tc = 1; tc <= t; tc++){
  152. //        cout << "Case #" << tc << ": ";
  153. //        solve();
  154. //        if(tc != t)
  155. //            cout << nl;
  156. //    }
  157.  
  158.     return 0;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement