MY CODE=> https://ide.codingblocks.com/s/243873
This is showing memory limit exceded for one test case .
I am using vector here but still if i choose a fixed size of 50,000 as given still it is showing MLE
MY CODE=> https://ide.codingblocks.com/s/243873
This is showing memory limit exceded for one test case .
I am using vector here but still if i choose a fixed size of 50,000 as given still it is showing MLE
@gagangoyal674
Time complexity of your code is O(N^3) since you have used 3 nested loops in multiply function. So your code is giving TLE for n>1000. Try to solve this question without using matrix exponentiation.
In hint this method is only suggested so can you suggest another approach
Hi In your code you need to pass the vector by reference in the recursive function. Passing it by value creates its numerous copies.
I tried that too but still nothing happened so I tried to change my logic
Now I am using jacobsthal series whose recurrence relation is linear and this is the multiplication of all the cows number sum except the present cow number and present cow number coeff is jcobsthal number ±1 depending on whether t is odd or even
My code for same is https://ide.codingblocks.com/s/246946