Hey Everyone, So I saw this problem in one of the contests on Codechef(link)
Problem Statement You are given two integers N and M. Find the number of sequences A1, A2,…,AN, where each element is an integer between 1 and M (inclusive) and no three consecutive elements are equal. Since this number could be very large, compute it modulo 109+7.
So I used my general code for Matrix Exponentiation but got a TLE.
My submission
People have used matrix exponentiation for the same and got a full score.
Selected submission
Things that I have tried already are
- Switching ll with int
- Reserving the size of the vector already.
Please tell me what I can optimize more in my code so that we do not face this problem in any of the Matrix Exponentiation problems?