×

# need help

 0 problem link:https://www.codechef.com/problems/TOMJER solution link: https://www.codechef.com/status/TOMJER,viralivora the solution is not getting accepted asked 24 Feb '17, 20:53 183●8 accept rate: 14%

 1 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 2.8k●1●4●19 accept rate: 16% thanks ^_^ (24 Feb '17, 21:53)
 0 @viral 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 hackerearth.com '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 15.5k●1●20●66 accept rate: 18%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×2,739
×2,476
×316

question asked: 24 Feb '17, 20:53

question was seen: 2,465 times

last updated: 24 Feb '17, 23:05