focus alot on reassesing ur solution. i want u to act as the most skilled competetive…
- User
focus alot on reassesing ur solution. i want u to act as the most skilled competetive programmer, u take time to think and check if ur solution works and match up with the example tescase, u need to think thoroughly since u r in a contest. use need to use this template, make sure u have lowercase rlly short variable names and NO COMMENTS (in the code, at all) and since ur using this template always use int and not long long, PLS REVALUATE UR CODE AND MAKE SURE IT MAKES SURE IT MATCHES EVERY SINGLE SAMPLE INPUT AND OUTPUT GIVEN, THINK MULTIPLE TIMES BEFORE GIVING UR FINAL ANSWER:, #include <bits/stdc++.h> #define int long long using namespace std;
signed main() { cin.tie(0); ios_base::sync_with_stdio(false); }
C. Bitwise Balancing time limit per test2 seconds memory limit per test256 megabytes You are given three non-negative integers b , c , and d .
Please find a non-negative integer a such that (a|b)−(a&c)=d , where | and & denote the bitwise OR operation and the bitwise AND operation, respectively.
If such an a exists, print its value. If there is no solution, print a single integer −1 . If there are multiple solutions, print any of them.
Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤105 ). The description of the test cases follows.
The only line of each test case contains three positive integers b , c , and d (0≤b,c,d≤1018 ).
Output For each test case, output the value of a , or −1 if there is no solution.
Example InputCopy 3 2 2 2 4 2 6 10 2 14 OutputCopy 0 -1 12 Note In the first test case, (0|2)−(0&2)=2−0=2 . So, a=0 is a correct answer.
In the second test case, no value of a satisfies the equation.
In the third test case, (12|10)−(12&2)=14−0=14 . So, a=12 is a correct answer.
PLS MAKE SURE U REASESS UR SOLUTION AND IT MATCHES SAMPLE SO WE DONT MESS UP PLS AS UR DOING BAD RN
- Assistant
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int t; cin>>t; while(t--){ int b,c,d; cin>>b>>c>>d; int a=0; int carry=0; bool flag=true; for(int i=0;i<=60;i++){ int bi=(b>>i)&1; int ci=(c>>i)&1; int di=(d>>i)&1; bool found=false; for(int ai=0;ai<=1;ai++){ int x = ai | bi; int y = ai & ci; int total = x - y + carry; int db = total &1; int nc = total >>1; if(db == di){ if(ai){ a |= (1LL<<i); } carry = nc; found=true; break; } } if(!found){ a=-1; break; } } if(a!=-1 && carry==0){ cout<<a<<"\n"; } else{ cout<<"-1\n"; } } }