Advertisement
El_GEMMY

a1

Apr 17th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.21 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, s; cin >> a >> b >> s;
  79.  
  80.     int cnt_and = 0, cnt_or = 0, cnt_xor = 0;
  81.     char c[n];
  82.  
  83.     for(auto& i : c)
  84.         i = '-';
  85.  
  86.     // &
  87.     for(int i = 0; i < n and cnt_and < x; i++){
  88.         if(a[i] == b[i] and a[i] == '0' and s[i] == '1')
  89.             return void(cout << "NO");
  90.  
  91.         bool ok = false;
  92.  
  93.         ok |= (a[i] != b[i] and s[i] == '0');
  94.         ok |= (a[i] == b[i] and a[i] == '1' and s[i] == '1');
  95.         ok |= (a[i] == b[i] and a[i] == '0' and s[i] == '0');
  96.  
  97.         if(ok and c[i] == '-'){
  98.             c[i] = '&';
  99.             cnt_and++;
  100.         }
  101.     }
  102.  
  103.  
  104.     // ^
  105.     for(int i = 0; i < n and cnt_xor < z; i++){
  106.         bool ok = false;
  107.  
  108.         ok |= (a[i] != b[i] and s[i] == '1');
  109.         ok |= (a[i] == b[i] and a[i] == '0' and s[i] == '0');
  110.         ok |= (a[i] == b[i] and a[i] == '1' and s[i] == '0');
  111.  
  112.         if(ok and c[i] == '-'){
  113.             c[i] = '^';
  114.             cnt_xor++;
  115.         }
  116.     }
  117.  
  118.     // |
  119.     for(int i = 0; i < n and cnt_or < y; i++){
  120.         bool ok = false;
  121.  
  122.         ok |= (a[i] == b[i] and a[i] == '1' and s[i] == '1');
  123.         ok |= (a[i] != b[i] and s[i] == '1');
  124.         ok |= (a[i] == b[i] and a[i] == '0' and s[i] == '0');
  125.  
  126.         if(ok and c[i] == '-'){
  127.             c[i] = '|';
  128.             cnt_or++;
  129.         }
  130.     }
  131.  
  132.  
  133.     bool ok = count(c, c + n, '-') == 0;
  134.  
  135.  
  136.     if(ok and cnt_and == x and cnt_xor == z and cnt_or == y){
  137.         cout << "YES" << nl;
  138.         for(auto& i : c)
  139.             cout << i;
  140.     }else{
  141.         cout << "NO";
  142.     }
  143. }
  144.  
  145. int main(){
  146.     Start_Crushing();
  147.  
  148.     int t = 1;
  149. //    /*Multiple test cases?*/ cin >> t;
  150.     while (t--) {
  151.         solve();
  152.         if(!t)
  153.             break;
  154.         cout << nl;
  155.     }
  156.  
  157. //    for(int tc = 1; tc <= t; tc++){
  158. //        cout << "Case #" << tc << ": ";
  159. //        solve();
  160. //        if(tc != t)
  161. //            cout << nl;
  162. //    }
  163.  
  164.     return 0;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement