@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ā¦
- Checking if it is greater than the element at right(otherwise sum of these two will become negative).
- Similarly checking if it is greater than left element.
- 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ā¦
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ā¦
whats the approach for st mincut can anyone explain ??
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?
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.
@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
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.