lina_os

Untitled

Jun 29th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define ul unsigned long long
  5. #define ld long double
  6. #define vll(v) vector<ll>v
  7. //#define vll(v,n) vector<ll>v(n);
  8. #define mll(m) map<ll,ll>m;
  9. #define sll(s) set<ll>s;
  10. #define iv(v) for(auto &i:v) cin >> i;
  11. #define ov(v) for(auto &i:v) cout << i << " ";
  12. #define all(v) (v.begin(),v.end());
  13. #define Bismillah ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  14.  
  15. using namespace std;
  16.  
  17. string toBin(ll n) {
  18.     string s;
  19.     while (n) {
  20.         s.push_back(n%2+'0');
  21.         n/=2;
  22.     }
  23.     reverse(s.begin(), s.end());
  24.     return s;
  25. }
  26.  
  27. ll toDec(string s) {
  28.     reverse(s.begin(), s.end());
  29.     ll n=0;
  30.     for (int i=0; i<s.size(); i++) {
  31.         n+=(s[i]-'0') * (1<<i);
  32.     }
  33.     return n;
  34. }
  35.  
  36. ll mul(ll a, ll b) {
  37.     ll mod=1e9+7;
  38.     return(((a%mod)*(b%mod))%mod);
  39. }
  40.  
  41. ll noz(string s) {
  42.     ll ans=0;
  43.     for (int i=0; i<s.length(); i++) {
  44.         if (s[i]=='0') ans++;
  45.     }
  46.     return ans+(6-s.length());
  47. }
  48.  
  49. ll lw,hg;
  50. bool can(ll i,ll n) {
  51.     if (i*(i+1)/2+n*(n+1)/2 <= hg && i*(i+1)/2+n*(n+1)/2 >= lw) return true;
  52.     return false;
  53. }
  54.  
  55.  
  56. void solve() {
  57.     ll n;
  58.     cin >> n;
  59.     string s (10,'x');
  60.     for (int i=0; i<n ;i++) {
  61.         char c;
  62.         ll nn;
  63.         cin >> c >> nn;
  64.         string x=toBin(nn);
  65.         reverse (x.begin(), x.end());
  66.         for (int j=0; j<x.size(); j++) {
  67.             if (c=='|') {
  68.                 if (x[j]=='1') s[j]='1';
  69.             }
  70.             else if (c=='^') {
  71.                 if (s[j]!='x') {
  72.                     if (s[j]==x[j]) s[j]='0';
  73.                     else s[j]='1';
  74.                 }
  75.             }
  76.             else {
  77.                 if (x[j]=='0') s[j]='0';
  78.             }
  79.         }
  80.         if (c=='&') {
  81.             for (int j=x.size(); j<10; j++) {
  82.                 s[j]='0';
  83.             }
  84.         }
  85.     }
  86.     string a,o;
  87.     for (int i=0; i<10; i++) {
  88.         if (s[i]=='x') {
  89.             a.push_back('1');
  90.             o.push_back('0');
  91.         }
  92.         else {
  93.             a.push_back(s[i]);
  94.             o.push_back(s[i]);
  95.         }
  96.     }
  97.     reverse(a.begin(), a.end());
  98.     reverse(o.begin(), o.end());
  99.     vector<pair<char,ll>>v;
  100.     if (count(a.begin(), a.end(), '1')!=10) {
  101.         v.push_back({'&',toDec(a)});
  102.     }
  103.     if (count(o.begin(), o.end(), '0')!=10) {
  104.         v.push_back({'|',toDec(o)});
  105.     }
  106.     cout << v.size() << endl;
  107.     for (auto i:v) cout << i.first << " " << i.second << endl;
  108. }
  109.  
  110. int main() {
  111.     Bismillah
  112.     ll t=1;
  113. //    cin >> t;
  114.     while (t--) {
  115.         solve();
  116.     }
  117.     return 0;
  118. }
  119.  
  120.  
Advertisement
Add Comment
Please, Sign In to add comment