need help



problem link:
solution link:,viralivora
the solution is not getting accepted


Just convert int to long long data type as your solution is going to be overflow. See my submitted solution. I just changed your code a little bit.



As bansal stated, the problem is in overflow.

Since h can be upto 50, this means ans may range upto 5.62 x 10^14!!

I would use a long long int for that.

And btw, I am curious, why did you make an array for answer, and print it separately in new loop in end?

A better implementation would be, to make a variable ‘ans’, use it in loop, like, ans = pow(2,k-1) and immediately print it.

Then when the loop runs again, it overrides previous value of ans with new value and again prints it.

The thing is, by making a separate loop to run the array, will take time. Although the constraints here are small, in case of large constraints, this implementation would give you a TLE while some other guy with same algo will get correct answer (This happens especially when judging criteria is strict, as in 's contest)

So to sum it up-

1. Use long long int to prevent possible overflow
 2. Try to optimize your code w.r.t time (and memory, though it doesn't make much difference in memory here)


thanks :slight_smile: