记录编号 369907 评测结果 AAAAAAAAAA
题目名称 [NOI 2014]起床困难综合症 最终得分 100
用户昵称 GravatarAntiLeaf 是否通过 通过
代码语言 C++ 运行时间 0.270 s
提交时间 2017-02-11 19:45:18 内存使用 1.05 MiB
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100010;
bool judge(unsigned,unsigned);
char c[15];
unsigned n,m,op[maxn]={0u},a[maxn],ans=0u;
int main(){
	freopen("sleep.in","r",stdin);
	freopen("sleep.out","w",stdout);
	scanf("%u%u",&n,&m);
	for(unsigned i=0u;i<n;i++){
		scanf("%s%u",c,&a[i]);
		if(!strcmp(c,"OR"))op[i]=1u;
		else if(!strcmp(c,"XOR"))op[i]=2u;
	}
	for(unsigned i=31u;~i;i--)if((ans|(1u<<i))<=m&&!judge(0,i)&&judge(1,i))ans|=1u<<i;
	for(unsigned i=0;i<n;i++){
		if(!op[i])ans&=a[i];
		else if(op[i]==1u)ans|=a[i];
		else ans^=a[i];
	}
	printf("%u",ans);
	return 0;
}
bool judge(unsigned x,unsigned k){
	for(unsigned i=0u;i<n;i++){
		if(!op[i])x&=(a[i]>>k)&1u;
		else if(op[i]==1u)x|=(a[i]>>k)&1u;
		else x^=(a[i]>>k)&1u;
	}
	return x;
}
/*
3 10
AND 5
OR 6
XOR 7
Answer:
7
*/