60pts,求调
查看原帖
60pts,求调
490831
_Kaedehara_Kazusha_楼主2024/11/25 20:12

代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
string a[100010];
int b[100010];
bool check(int now,int x){
	for(int i=1;i<=n;i++){
		if(a[i]=="AND")
			now&=b[i];
		else if(a[i]=="OR")
			now|=b[i];
		else
			now^=b[i];
	}
	return (now>>x)&1;
}
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i]>>b[i];
	int now=0,ans=0;
	for(int i=32;i>=0;i--){
		if(now+(1<<i)>m)
			continue;
		if(check(0,i))
			ans+=1<<i;
		else if(check(1<<i,i))
			ans+=1<<i,now+=1<<i;
	}
	cout<<ans<<endl;
	return 0;
}
2024/11/25 20:12
加载中...