let's start Code

Lost Numbers

Lost Numbers

Solution 01: partially AC


#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
long long Xorr, andd, orr;
cin >> orr >> Xorr >>andd;
long long a = 0,b = 0;
int f = 1;
for(int i = 0; i <= 60; i++){
long long tem = 1 << i;
if(tem > Xorr && tem > orr && tem > andd) break;
if(Xorr & (1 << i)){ // Xor 1
if( (andd & (1 << i)) == 0 && (orr & (1 << i)) == 1) a += 1 << i; // and 1 hote hobe
else {
cout << -1<<endl;
f = 0;
break;
}
}
else{ // xor 0
if(andd & (1 << i)){ // and 1 hole
if(orr & (1 << i)){
a += 1 << i;
b += 1 << i;
}
else {
cout << -1<<endl;
f = 0;
break;
}
}
else{ // and 0 hole
if(orr & (1 << i)){ // or 1 hobena
cout << -1<<endl;
f = 0;
break;
}
}
}
}
// cout << orr << " " << andd << endl;
if(f)
cout << a << " "<<b<<endl;
}
return 0;
}

Solution 02:



#include<bits/stdc++.h>
using namespace std;
int main()
{
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
long long orr, annd, xorr;
cin >> orr >> xorr >> annd;
if(xorr & annd || orr != xorr + annd) cout << -1<<endl;
else cout << orr << " "<<annd<<endl;
return 0;
}
Share:

Related Posts:

No comments:

Post a Comment

About

let's start CODE

Popular Posts