First of all, I think your solution should give TLE as it is O((nnn*n )/16) for the case when k = n/2. You got WA because even in small test case your code isn’t giving a correct answer. I think it is because of the collision in hashing as your mod value is small and your hash is not strong enough.
Your solution is not giving TLE because you are getting WA on the 1st test case. Test cases with larger constraints are not being judged. But when it will be judged it will eventually give TLE.
The hashing technique mentioned in that post is good for that question because we are trying to find only 1 mismatch. But for a strong hash function you have to use a good prime value and good MOD value, maybe 2 sometimes. But with unsigned long long int data type in C++ we can allow a large range of value to be assigned as hash and less chance of collision. Go through the above post I suggested.