题解:AT_abc347_d [ABC347D] Popcount and XOR
解决
题意
您将得到非负整数
确定是否有一对非负整数
-
0 \le X \lt 2^{60} -
0 \leq Y \lt 2^{60} -
\operatorname{popcount}(X) = a -
\operatorname{popcount}(Y) = b -
X \oplus Y = C
思路
首先要满足
细节
-
判断当
a 和b 的位数减去构成C 要用的位数后如果是奇数个,那么说明之后不能通过选取同一个位数相互抵消。 -
判断
a 和b 能否用完,用不完也是不行的。 -
开
long long -
代码
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define int_128 __int128
#define lowbit(x) (x&(-x))
using namespace std;
int a,b,c;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>a>>b>>c;
int cnt=0;
int x=c;
while(x) {
x-=lowbit(x);
cnt++;
}
if(a+b<cnt || (a+b-cnt)%2==1) {
cout<<-1;
}
else {
int ans=0,anss=0;
for(int i=0;i<=60;i++){
if(c&(1ll<<i)){
if(a>=b){
ans|=(1ll<<i);
a--;
}
else {
anss|=(1ll<<i);
b--;
}
}
}
for(int i=0;i<=60;i++){
if((c&(1ll<<i)) == 0){
if(a&&b){
a--;
b--;
ans|=(1ll<<i);
anss|=(1ll<<i);
}
else {
break;
}
}
}
if(a||b){
cout<<-1;
}
else cout<<ans<<" "<<anss<<"\n";
}
return 0;
}