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

×

time limit

how can i reduce its running time, here's the code http://www.codechef.com/viewsolution/2224775 ???? for the question http://www.codechef.com/problems/ARRANGE.

asked 10 Jun '13, 19:55

aasthi's gravatar image

3★aasthi
30359
accept rate: 0%

edited 11 Jun '13, 08:26


@aasthi >> Well, it was said that

The straightforward approach of writing a function that simply reverses the bits of an index to get the new index suffices (recalling that indices with fewer bits than k are padded with leading zeros). The complexity of this algorithm is O(n log n) where n = 2^k is the length of the string. While this was fast enough for the contest, an O(n) algorithm can be devised using a slighly more clever approach.

But still your solution is failing maybe due to slowness of Java or some other reason. You should have a look at how to make this algorithm run in O(n). Here is the editorial for the same.

link

answered 11 Jun '13, 12:01

bugkiller's gravatar image

3★bugkiller
8.7k194898
accept rate: 9%

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:

×717

question asked: 10 Jun '13, 19:55

question was seen: 968 times

last updated: 11 Jun '13, 12:01