You are not logged in. Please login at to post your questions!


need help

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

asked 24 Feb '17, 20:53

viralivora's gravatar image

accept rate: 14%

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.


answered 24 Feb '17, 21:02

bansal1232's gravatar image

accept rate: 16%

edited 24 Feb '17, 21:03

thanks ^_^

(24 Feb '17, 21:53) viralivora4★


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)

answered 24 Feb '17, 23:05

vijju123's gravatar image

5★vijju123 ♦♦
accept rate: 18%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 24 Feb '17, 20:53

question was seen: 2,465 times

last updated: 24 Feb '17, 23:05