记录编号 369805 评测结果 AAAAAAAAAA
题目名称 [NOI 2014]起床困难综合症 最终得分 100
用户昵称 GravatarRapiz 是否通过 通过
代码语言 C++ 运行时间 0.338 s
提交时间 2017-02-11 12:13:16 内存使用 1.46 MiB
显示代码纯文本
#include <cstdio>
#define file(x) "sleep." #x
const int N = 1e5 + 10;
int n, m, arg[N], dam, num;
char op[N][10];
int calc(int x, int p){
	for (int i = 1; i <= n; i++) {
		int d = arg[i] >> p & 1;
		if (op[i][0] == 'O') x |= d;
		else if (op[i][0] == 'X') x ^= d;
		else if (op[i][0] == 'A') x &= d;
	}
	return x;
}
int main() {
	freopen(file(in), "r", stdin);
	freopen(file(out), "w", stdout);
	scanf("%d%d", &n,&m);
	for (int i = 1; i <= n; i++) scanf("%s%d", op[i], arg + i);
//	int k = 0;
//	while (1 << k + 1 <= m) k++;
	for (int i = 30; i >= 0; i--) {
		int t1 = calc(1, i), t0 = calc(0, i);
//		printf("%d %d\n", t1, t0);
		if (t1 > t0 && (num | (1 << i)) <= m) num |= 1 << i, dam += t1 << i;
		else dam += t0 << i;
	}
	printf("%d", dam);
}