This editorial belongs to a closed contest held for Kendriya Vidyalaya, Aurangabad school. Also, for the domain of students participating, the problems were kept simple. So, you can safely skip this editorial.
Author: Abhinav Kaushlya
Tester: Abhinav Kaushlya
Editorialist: Abhinav Kaushlya
The problem asks you to convert the binary string into an integer provided that it stays within the INT bound.
We can do this by simply computing the value of each bit as integer, summing it for all bits, and then printing it.
First task would be to compute the value of each bit of given binary string to its corresponding integer value and then summing the value to the final value which will represent the final value of the binary string in its integer representation. We can do this by simply iterating over to all bits maybe from behind and then multiplying the bit value with multiplier and then adding that value to our ans. We also need to multiply the multiplier by 2 so as to generate the new multiplier for the next bit. While iterating over the bits we can check each time if the new value (ans) is greater than INT_MAX, if it is then we simply break out of the loop and print ‘overflow’ as required in the problem. For this detection we shall use ‘long’ instead of int for simplicity. Finally we need to print the value of the ans.
There are several ways of solving this problem and its super easy to implement. But seeing the domain of participating students we kept it simple enough to solve.
AUTHOR’S AND TESTER’S SOLUTIONS:
Author’s solution can be found here.
Tester’s solution can be found here.