记录编号 127646 评测结果 AAAAAAAAAA
题目名称 [NOI 2014]起床困难综合症 最终得分 100
用户昵称 GravatarAsm.Def 是否通过 通过
代码语言 C++ 运行时间 0.130 s
提交时间 2014-10-15 23:23:40 内存使用 1.08 MiB
显示代码纯文本
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>
#define maxn ((int)1e5 + 4)
using namespace std;
typedef unsigned int uint;
#if defined DEBUG
FILE *in = fopen("test", "r");
#define out stdout
#else
FILE *in = fopen("sleep.in", "r");
FILE *out = fopen("sleep.out", "w");
#endif
inline void getint(int &x){
	char c = fgetc(in);
	while(!isdigit(c))c = fgetc(in);
	x = c - '0';
	while(isdigit(c = fgetc(in)))x = x * 10 -'0' + c;
}
int n, m, t[maxn], op[maxn];
inline int getop(){
	char c = fgetc(in);
	int ans;
	while(!isalpha(c))c = fgetc(in);
	if(c == 'O')ans = 0;
	else if(c == 'X')ans = 1;
	else if(c == 'A')ans = 2;
	while(isalpha(c))c = fgetc(in);
	return ans;
}
inline int calc(int x){
	int i;
	for(i = 0;i < n;++i){
		if(op[i] == 0)x |= t[i];
		else if(op[i] == 1)x ^= t[i];
		else x &= t[i];
	}
	return x;
}
int main(){
	int i;
	uint ans = 0, it = ((uint)1 << 31);
	getint(n),getint(m);
	for(i = 0;i < n;++i){
		op[i] = getop();
		getint(t[i]);
	}
	bool ok1 = 0;
	int calc0 = calc(0);
	while(it){
		if(calc0 & it){
			ans += it;
			if(it & m)ok1 = 1;
		}
		else if((ok1 || it & m) && (calc(it) & it))
			ans += it;
		else if(it & m)ok1 = 1;
		it >>= 1;
	}
	fprintf(out, "%u\n", ans);
	return 0;
}