Invitation to CodeChef May Long Challenge 2018!

@swetankmodi You are an observer! :wink:

1 Like

Or perhaps-

4th May 2018 to 14th February, 2019.

I notice how the contest is ending abruptly at Valentines day. Chef will be busy or what? :stuck_out_tongue:

@swetankmodi 14th February is a very nice day :slight_smile: Not only time :smiley:

Thanks, fixed.

1 Like

Very true @mgch . There are usually back to back 3-4 contests in a row that day. Very nice day indeed :slight_smile: :stuck_out_tongue: :stuck_out_tongue:

@vijju123 you should prevent time travel before the blog will be posted for the next time! :smiley:

1 Like

XDXDXD.

I’ll do whatever is in my power to stop that :stuck_out_tongue: XD :slight_smile:

@vijju123 it’s fun to take part on the contests that day since most of us are free :stuck_out_tongue:

@mgch Welcome :slight_smile:

2 Likes

never got that opportunity :stuck_out_tongue:

Solving div2 Questions from div1 will not affect your ratings. In case they do, it will be a bug and you can get opportunity of getting codechef laddus from @admin :stuck_out_tongue: X)

2 Likes

Besides, @vijju123, @mgch, @admin, please add problems to practice section.

@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?

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

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!!

@l_returns, Thanks for cool explaination.

1 Like