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

×

[closed] Plz help solving COOLING Problem??....newbie to codechef

Guys, I have tried solving Cooling problem with many inputs and I even get the desired output on my pc, but still getting "wrong answer" on code chef. Here is my code.

@ http://www.codechef.com/viewsolution/2700993

asked 23 Sep '13, 00:12

silvercrypt's gravatar image

0★silvercrypt
10113
accept rate: 0%

closed 09 Dec '13, 10:02

kunal361's gravatar image

4★kunal361
6.0k133272

The question has been closed for the following reason "The question is answered, right answer was accepted" by kunal361 09 Dec '13, 10:02


in your bubble sort code u r also considering a[n] when i=0 and j=n-1. so if a[n] is initiated by previous test cases then your code will fail. i just initiated a[n] to 1000000000 and submitted your code and got accepted. my submission http://www.codechef.com/viewsolution/2707109. also a small suggestion try to use std::sort() and std:swap() in your code.

link

answered 23 Sep '13, 08:26

abhinav1234's gravatar image

4★abhinav1234
47045
accept rate: 40%

didn't get? how code fails if a[n] initiated by previous test case??...It would be pretty kind of you to explain me out in this regard..........newys thanks bro for your useful suggestion :)

(23 Sep '13, 22:49) silvercrypt0★
1

consider the test case
2
4
1 10 20 30
1 10 20 30
3
10 20 30
10 20 30
->for first test case in bubble sort code a[4] is also considered while sorting but a[4] is not assigned any value so it considers a garbage value for a[4].
after first test case execution wr[]-> "0 0 0 0".
->for second test case after input wr[] -> "10 20 30 0" after sorting wr[] -> "0 10 20 30"(since you are also considering a[3] which is assigned value 0 instead of getting "10 20 30 0" your wr[] will be "0 10 20 30".
so the ans will be printed as 2 instead of 3. hope this helps :)

(24 Sep '13, 06:28) abhinav12344★

thnkx bro..got it..:)

(26 Sep '13, 01:00) silvercrypt0★

Hey change bubble sort to quick sort i have done same in your code and got AC


you can see my submission http://www.codechef.com/viewsolution/2706803


link

answered 23 Sep '13, 02:10

nitish1402's gravatar image

3★nitish1402
31115
accept rate: 0%

i'm not into c language, but the potential reason why you might be getting WA, is the special cases which you need to think about separately and then handle. also while testing your code on pc, you might not be testing it for those cases hence getting right answer. So, think again, this time a little deep. -all the best

link

answered 23 Sep '13, 01:42

codeanindya's gravatar image

1★codeanindya
855817
accept rate: 0%

NOTE: in my opinion, it would be nice if you count++ inversely. assume weight is X, and limit is Y func respectively. we have(or reach) our desired count++ when Y's element is bigger than or equal to X's particular element. and in that condition we count++. otherwise, we just pass onto Y's next element, till we meet the condition.

link

answered 09 Dec '13, 10:00

garakchy's gravatar image

1★garakchy
1.1k163048
accept rate: 1%

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,647
×134
×29

question asked: 23 Sep '13, 00:12

question was seen: 989 times

last updated: 09 Dec '13, 10:02