90pts WA on #6 玄关求调
查看原帖
90pts WA on #6 玄关求调
741244
Eason_cyx大愚若智楼主2025/1/22 10:32

rt,正确的答案是 131071,我的输出 131070

#include <bits/stdc++.h>
#define int long long
using namespace std;
int ans[32][2];
signed main() {
	int n, m; cin >> n >> m; int wei = log2(m); 
	for(int i = 1;i <= wei;i++) ans[i][1] = 1;
	for(int i = 1;i <= n;i++) {
		string opt; int x; cin >> opt >> x;
		if(opt == "AND") {
			for(int j = 0;j < 31;j++) ans[j][0] &= x % 2, ans[j][1] &= x % 2, x >>= 1;
		} else if(opt == "OR") {
			for(int j = 0;j < 31;j++) ans[j][0] |= x % 2, ans[j][1] |= x % 2, x >>= 1;
		} else {
			for(int j = 0;j < 31;j++) ans[j][0] ^= x % 2, ans[j][1] ^= x % 2, x >>= 1;
		}
	} int now = 1, Ans = 0; for(int i = 0;i < 31;i++, now *= 2) {
		if(ans[i][0]) Ans += now;
		else {
			if(!ans[i][1]) continue;
			else if((1ll << i) <= m) m -= (1ll << i), Ans += now;
		}
	} cout << Ans << endl;
	return 0;
}
2025/1/22 10:32
加载中...