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

×

need help

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

viralivora's gravatar image

4★viralivora
1838
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.

link

answered 24 Feb '17, 21:02

bansal1232's gravatar image

5★bansal1232
2.8k1419
accept rate: 16%

edited 24 Feb '17, 21:03

thanks ^_^

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

@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)
link

answered 24 Feb '17, 23:05

vijju123's gravatar image

5★vijju123 ♦♦
15.5k12066
accept rate: 18%

toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×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