Lost Numbers
Solution 01: partially AC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
No comments:
Post a Comment