Was really a tough question to crack. I had heard of bitset earliar but never used it. Tried to read it concept during the contest but couldn’t understand it properly. But then got a link to this Marking large integers - general - CodeChef Discuss which helped a lot. I also tried to use unordered map (which is available in C++14 as C++4.9.2 gave compile error) but in some worst case in give O(n) complexity due to rehashing. So, I avoided it.
Finally, a very naive implementation of the idea given in the above link helped to get AC. (although the 2ns input provided- 10000000 777777777 777777777 777777777, took 2.16 sec on Codechef ide and 2.37 sec on my computer to run). So, just to try my luck, at the last moments of the contest, i made and submission and was happy to get AC on the first attempt.
When I run this code CodeChef: Practical coding for everyone on my machine, codechef compile and run or ideone it is showing memory exhausted so how do I run this code?
this problem shows how much u know about max size of arrays in programming .
we can make 2^30 size bool array in c++
but if we use vector then this size goes up to 2^33, in this question we need 2^31 bool values,
so this problem can be solved by using
Plz someone help me in this. I am unable to run this code. As O(10^8) memory can be allocated but this is O(10^10), though I know bitset takes 1/8 of actual memory but still order becomes O(10^9) still memory exhaustion remains.
However this code got accepted so plz help me in this.
While Calculating si=(si-1*a+b)mod2*32.We can get overflow in (si-1*a) as well right.Also not able to understand here how compiler handles overflow.can you please explain it
Actually I guess, the author is referring to the situation where we are inserting s/2 and not s. So 31 bits are sufficient. Though si value needs 32 bits, si/2 needs only 31 bits.