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

×

WA in KCHAR

I got partially correct answer in KCHAR.
Link to the Question : KCHAR
Link to my solution : link
Please point out my mistake and try to debug my code. Also, as I am getting correct answer in small input size, have I made any mistakes in data types? Please clarify my doubts.
Thank you :)

EDIT : Got AC. Thanks to @abhikalpu_123 and @raj79 for help. Appreciate it! Thanks!

asked 05 Jul '17, 14:13

dishant_18's gravatar image

5★dishant_18
61419
accept rate: 12%

edited 05 Jul '17, 15:08


Answer is hidden as author is suspended. Click here to view.

answered 05 Jul '17, 14:29

raj79's gravatar image

1★raj79
(suspended)
accept rate: 10%

Ya I know, Thanks! Well I found a pattern for all indexes. All even index(say k) have same character as their (better) halves :p (i.e k/2). Now for odd index, the character at odd index is different from the difference of character at the next greatest power of 2 and the index(i.e p(power of 2>k) - k). And then I ran a recursive function to find the answer.

I know I am bad at explaining but I tried my best!!

(05 Jul '17, 14:48) dishant_185★

i guess you are complicating things enough in your code , and this will not be running for 10e18 as @abhikalpu_123 said. your logic is right , but it fails at higher values. while(n%2==0) n/=2; if (n%4==1) print a else print c, it was as simple as that , an overview of your logic actually. i did the same as your logic , but in a normal while loop. this will eazily run , just use long long int

(05 Jul '17, 14:56) raj791★

I just had a array 1 size smaller as @abhikalpu_123 pointed out!! Got AC now.. Thanks for the help though :)

(05 Jul '17, 15:06) dishant_185★

The max value of K can be up to 10^18 But your code is handling up to 2^59 i.e. 5*10^17. In your above code make increase the length of array $a$ to 61 instead of 60. (and corresponding changes like making every for loop i<61). As @raj97 said its quite tough but im in a vaccation :D

link

answered 05 Jul '17, 14:48

abhikalpu_123's gravatar image

5★abhikalpu_123
1475
accept rate: 8%

Or simply, find and replace 61 by 60. :P

(05 Jul '17, 14:51) abhikalpu_1235★

Thanks for analysis of the code :) Urghh when will I stop making small mistakes!

Thanks for the help man... Appreciate it :)

(05 Jul '17, 14:57) dishant_185★
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:

×1,070
×135

question asked: 05 Jul '17, 14:13

question was seen: 522 times

last updated: 15 Dec '17, 14:45