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

×

Help in Dynamic Inversion of June Lunchtime

The following solution is accepted as correct solution in the practice link of the question , But when i submitted the same Code during the contest with int inv=0; statement declared outside the while loop it was not accepted , Why??

asked 29 Jun '14, 16:35

mrajesh016's gravatar image

1★mrajesh016
300227
accept rate: 0%

edited 29 Jun '14, 17:23


When you are putting the statement inv=0 , outside the loop , it is not initialised everytime , so it will keep on adding everytime and give wrong answer . For example if for 1st query answer is 1 for second answer is also 1 , if you donot initialise it to zero for the second time , it will give 2 as answer which is wrong . Hope it helps .

link

answered 29 Jun '14, 17:00

the65bit's gravatar image

4★the65bit
1.1k101328
accept rate: 13%

edited 29 Jun '14, 17:01

@the65bit is right.. but one more thing inv will be long long not int.. i got WA in 2 cases because of that..

link

answered 29 Jun '14, 17:30

i_am_what_i_am's gravatar image

6★i_am_what_i_am
652
accept rate: 10%

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,698
×530
×332

question asked: 29 Jun '14, 16:35

question was seen: 808 times

last updated: 29 Jun '14, 17:30