Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ul unsigned long long
- #define ld long double
- #define vll(v) vector<ll>v
- //#define vll(v,n) vector<ll>v(n);
- #define mll(m) map<ll,ll>m;
- #define sll(s) set<ll>s;
- #define iv(v) for(auto &i:v) cin >> i;
- #define ov(v) for(auto &i:v) cout << i << " ";
- #define all(v) (v.begin(),v.end());
- #define Bismillah ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- using namespace std;
- string toBin(ll n) {
- string s;
- while (n) {
- s.push_back(n%2+'0');
- n/=2;
- }
- reverse(s.begin(), s.end());
- return s;
- }
- ll toDec(string s) {
- reverse(s.begin(), s.end());
- ll n=0;
- for (int i=0; i<s.size(); i++) {
- n+=(s[i]-'0') * (1<<i);
- }
- return n;
- }
- ll mul(ll a, ll b) {
- ll mod=1e9+7;
- return(((a%mod)*(b%mod))%mod);
- }
- ll noz(string s) {
- ll ans=0;
- for (int i=0; i<s.length(); i++) {
- if (s[i]=='0') ans++;
- }
- return ans+(6-s.length());
- }
- ll lw,hg;
- bool can(ll i,ll n) {
- if (i*(i+1)/2+n*(n+1)/2 <= hg && i*(i+1)/2+n*(n+1)/2 >= lw) return true;
- return false;
- }
- void solve() {
- ll n;
- cin >> n;
- string s (10,'x');
- for (int i=0; i<n ;i++) {
- char c;
- ll nn;
- cin >> c >> nn;
- string x=toBin(nn);
- reverse (x.begin(), x.end());
- for (int j=0; j<x.size(); j++) {
- if (c=='|') {
- if (x[j]=='1') s[j]='1';
- }
- else if (c=='^') {
- if (s[j]!='x') {
- if (s[j]==x[j]) s[j]='0';
- else s[j]='1';
- }
- }
- else {
- if (x[j]=='0') s[j]='0';
- }
- }
- if (c=='&') {
- for (int j=x.size(); j<10; j++) {
- s[j]='0';
- }
- }
- }
- string a,o;
- for (int i=0; i<10; i++) {
- if (s[i]=='x') {
- a.push_back('1');
- o.push_back('0');
- }
- else {
- a.push_back(s[i]);
- o.push_back(s[i]);
- }
- }
- reverse(a.begin(), a.end());
- reverse(o.begin(), o.end());
- vector<pair<char,ll>>v;
- if (count(a.begin(), a.end(), '1')!=10) {
- v.push_back({'&',toDec(a)});
- }
- if (count(o.begin(), o.end(), '0')!=10) {
- v.push_back({'|',toDec(o)});
- }
- cout << v.size() << endl;
- for (auto i:v) cout << i.first << " " << i.second << endl;
- }
- int main() {
- Bismillah
- ll t=1;
- // cin >> t;
- while (t--) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment