Invitation to CodeChef May Long Challenge 2018!

@l_returns, How did u reduce the given problem to max sum subsequence such that no two adjacent elements are taken? Can u explain in bit detail?

Why my soln is giving WA in two test cases??
Please Help!!

ques - DBFB

Soln - soln

There are multiple issues with your code, i wonā€™t tell you the exact issues. But i would recommend you to clean your code first and use MOD whenever required. Read each expression in your code and ask yourself whether the MOD operation is really required.
One example is this line:
base_f[i] = (base_f[i - 1] MOD + base_f[i - 2] MOD) % MOD;
base_f[i - 1] is already smaller than MOD so using another mod just makes it messy.

Once you do that, submit again and if your solution is still failing link back your latest solution in comment and i will help.

Still giving WA on those two cases.

You missed my point, i want you to read each line if your code and remove extra modulo operations. Once you do that you will probably be able to find your mistake. So remove all extra modulo operations first and give link to your cleaned up code.

@vivek_shah98
yeah sureā€¦ if I make an element negative then I have to check three conditionsā€¦

  1. Checking if it is greater than the element at right(otherwise sum of these two will become negative).
  2. Similarly checking if it is greater than left element.
  3. no assume I have an array like 5 2 3 2 7 then both 2ā€™s follow upper conditions but if make both negative then (-2)+3+(-2) will become negative hence this is the third case which we will have to check(sum of two alternate numbers following above two condition is less than middle element).

If the case is like 2 3 2 3 2 3 2 then we cannot make all 2ā€™s negative. Instead we can imagine an array of 2 2 2 2 (skipping middle elements) and now It reduces to problem of max sum subsequence as if we make elements negative in 2 2 2 2
such that no two are adjacent then 3rd condition will be followed and (-2)+3+2 OR 2+3+(-2) wonā€™t be negativeā€¦

If it follows this three conditions then the sum of elements all subarrays having length greater than 1 will be strictly positiveā€¦

1 Like

well i suggest u to check if u r missing any modulo where its neededā€¦ if u r multiplying (10^910^910^9)%mod then it would be wrongā€¦ u should multiply any two and then multiply furtherā€¦

please Check this one -
https://www.codechef.com/viewsolution/18569255

whats the approach for st mincut can anyone explain ??

1 Like

Good!

Check these problematic lines

ll x = (b[i] - b[1]) % MOD ;

ll x = (a[i] - a[1]) % MOD;

sum = (1LL * pre_fib[n - 1] MOD * x * m) MOD;

gosh!!! now getting WA!! Life is hell!!

Cannot find the editorial of ST-MINCUT? Could someone please share the link?

@l_returns, Thanks for cool explaination.

1 Like

i checked you recent submission, these lines are still incorrect.

ll x = (b[i] - b[1]) MOD ; this can go negative so re write it as ll x = (b[i] - b[1] + MOD) MOD ; and same for the next line.

sum = (1LL * pre_fib[n - 1] MOD * x * m) MOD; This can cause integer overflow because you are multiplying 3 integers of magnitude 10^9 so re write it as, sum = (pre_fib[n - 1] * 1LL * x MOD) * m MOD;

Check for above two mistakes in full code, hope this helps.

Could anybody point out what is wrong with this solution for FAKEBS.

@vijju123 I was in div-1 and got 107 rank will I get 300 laddus ? I set filter to India in ranklist and if 20 different rank values are considered then I should get them.

welcome :slight_smile:

I donā€™t know python much but ur algo seems correctā€¦

There were lots of conditions involved in that question. But even on missing some, at least some cases passed. Dont know python, but I advise checking up others solution for reference.

I will confirm this with @admin and get back to you. :slight_smile: