# | User | Rating |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 165 |
3 | adamant | 161 |
4 | TheScrasse | 160 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | orz | 146 |
9 | SecondThread | 145 |
9 | pajenegod | 145 |
Name |
---|
it is a difficult to say why you have wrong answer ,but the main idea to solve this problem is different. You must precalculate this numbers . The size of this numbers is not big. Maximum 31*31. You can add this numbers to vector and then sort it. After that ,with binary search you must to take three numbers and then print minimum difference.
Even binary search is not required, linear search would work according to constraints.
Definitely, linear search would work here. But it's no harm to use optimisations.In the worst case (my favourite Big Oh :p), it only helps you discover something new eventually, which one never knows, might help in the future.
It is good for learning but sometimes constraints make problem and code more simple :P
Yeah, but those 105 upper limit of constraint was a headache. I too went with the binary search for it.
yeah ,really ))) i forgot about that,when i was solving a problem.
Your code doesn't work for the these numbers 15 63 127 255 511 have you got the pattern? These are one less than the power of two and greater than 7. Your code returns 1 but the actual answer is 2.
Bro, just an advice. Don't go with so much complex logics. It never helps but just increases chances of getting WA as evident in your case. Even I suffered a lot because of the same habit. So try to think easy.
Coming to the code, I'll think on this and let you know if I find the mistake.
Till then. What I thought of the solution to the problem is that till 10^9, there will be at most 450 such numbers which are the sum of two numbers (different powers of 2). And note the optimal number can even exceed 10^9. So for safety take till 2*10^9. And then apply binary search to find the closest such number or the optimal number and accordingly calculate the answer.
There is really no need for such complex code or binary search. You can just iterate through the values of 2^x + 2^y for (x != y), then you simply take the minimum difference between n and the computed sum. It should run in O(30*30).
Nice, I went with binary search during the contest. I like your approach greatly. Tell me if it worked, because if I ever thought of that I would have died thinking if something near 10^8 calculation will throw TLE or not.
Bro, it's not even 30*30. It's 30C2 = (30*29)/2 = about 450.
So number of operations in the worst case = about 4.5 * 10^7
Due to still think, It will get you a TLE? :P
I agree with you. Didn't think that clearly during the contest.
Here is the link to my solution. Solution