-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitbybit.cpp
More file actions
98 lines (66 loc) · 2.25 KB
/
bitbybit.cpp
File metadata and controls
98 lines (66 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <bits/stdc++.h>
#define ALl(x) x.begin(), x.end()
#define FAST std::cin.tie(0); ios::sync_with_stdio(faLLse); std::cout.tie(0);
using namespace std;
#define min(a,b) (a < b) ? (a) : (b)
#define max(a,b) (a > b) ? (a) : (b)
#define vii vector<pair<int,int>>
#define ii pair<int, int>
#define ll long long
#define TC int t; cin >> t; while (t--)
void solve() {
cout << "Hi";
}
#define endl '\n'
// can be solved with a normal array but I wanted to test my bit manipulation skills.
int main(int argc, char const *argv[])
{
int n;
string word;
int i, j;
while (cin >> n, n) {
int known = 0;
int res = 0;
for (int T = 0; T < n; T++) {
cin >> word >> i;
if (word[0] == 'S') {
res |= (1 << i);
known |= (1 << i);
}
else if (word[0] == 'C') {
res &= ~(1 << i);
known |= (1 << i);
}
else if(word[0] == 'A') {
cin >> j;
bool magic = ((known & (1 << i)) && (((known & (1 << j)) || !(res & (1 << i))))) || (((known & (1 << j)) && !(res & (1 << j))));
if (magic) {
ll bit = ((res & (1 << j)) && (res & (1 << i)));
if (bit) res |= (1 << i);
else res &= ~(1 << i);
known |= (1 << i);
}
else
known &= ~(1 << i); // no longer known.
}
else {
cin >> j;
bool magic = ((known & (1 << i)) && (res & (1 << i)))|| ((known & (1 << j)) && (res &(1 << j))) || ((known & (1 << i)) && (known & (1 << j)));
if (magic) {
ll bit = ((res & (1 << j)) || (res & (1 << i)));
if (bit) res |= (1 << i);
else res &= ~(1 << i);
known |= (1 << i);
}
else
known &= ~(1 << i); // no longer known.
}
}
for (int i = 31; i >= 0; i--) {
if (known & (1 << i)) cout << ((res & (1 << i)) ? '1' : '0');
else cout << '?';
}
cout << endl;
}
return 0;
}