a^b
64位整数乘法
最短Hamilton路径
起床困难综合征
知识点:二进制位运算的独立性,贪心
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=int(j);i<=int(k);i++)
#define per(i,j,k) for(int i=int(j);i>=int(k);i--)
typedef long long ll;
const int N = 100010;
int n, m;
char op[N][5];
int t[N];
int get(int pos, int val) {
rep(i,1,n) {
switch (op[i][0])
{
case 'A':
val &= t[i] >> pos & 1; break;
case 'O':
val |= t[i] >> pos & 1; break;
case 'X':
val ^= t[i] >> pos & 1; break;
}
}
return val;
}
int main(){
scanf("%d%d", &n, &m);
rep(i,1,n) scanf("%s%d", op[i], &t[i]);
int rs = 0, x = 0;
per(i,30,0) {
int r0 = get(i, 0), r1 = get(i, 1);
if(r0 == 1) {
rs += 1 << i;
} else if(r1 == 1 && x + (1 << i) <= m) {
rs += 1 << i;
x += 1 << i;
}
}
printf("%d\n", rs);
}