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

×

[closed] SPOJ FREQUENT WA

asked 23 Dec '14, 13:03

abeyaar's gravatar image

1★abeyaar
33422140
accept rate: 30%

closed 23 Dec '14, 15:35

The question has been closed for the following reason "The question is answered, right answer was accepted" by abeyaar 23 Dec '14, 15:35


In line 58-
parent.freq1=left_child.freq1+right_child.freq1*(FREQUENT.a[mid]==FREQUENT.a[parent.start]?1:0); parent.freq2=right_child.freq2+left_child.freq2*(FREQUENT.a[mid+1]==FREQUENT.a[parent.end]?1:0);
Dont u think it should be mid+1 in the first line and mid in the second? Like-
parent.freq1=left_child.freq1+right_child.freq1*(FREQUENT.a[mid+1]==FREQUENT.a[parent.start]?1:0); parent.freq2=right_child.freq2+left_child.freq2*(FREQUENT.a[mid]==FREQUENT.a[parent.end]?1:0); You add the right parts frequency only when the first value in right subtree is same as the first value in the parent. Likewise for the other part. Your given code fails here: https://ideone.com/d3zEqv The correct answer is 5 Do upvote if this helps :) Happy Coding! :)
link

answered 23 Dec '14, 14:38

shivam1511's gravatar image

5★shivam1511
4382414
accept rate: 22%

edited 23 Dec '14, 14:43

Thanks got AC. :) . Can you look into this?? http://discuss.codechef.com/questions/59332/spoj-gss2-wa

(23 Dec '14, 15:35) abeyaar1★
Umm sure..do u mind accepting my answer? :D
I would really appreciate that!
(23 Dec '14, 20:52) shivam15115★

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,768
×1,138

question asked: 23 Dec '14, 13:03

question was seen: 1,157 times

last updated: 23 Dec '14, 20:53