Hi!
I tried to solve this problem using BFS technique, and it seems that my code has passed test cases of huge number of inputs. However, it didn't pass the test case number 12. I don't know what is the fault I fell in it, because I can't trace this test case as it contains huge number of inputs and at the same time not completely shown. If someone can find the logical problem in my code, I hope to tell me what it is.
Problem: https://codeforces.net/problemset/problem/580/C
My solution: https://codeforces.net/contest/580/submission/124986838
Edit (the correct code):
The problem was in pushing the nodes that passed the number of consecutives positions of cats m. The correct submission is here after one of the users found the problem, thanks to him!
corrected submission: https://codeforces.net/contest/580/submission/124994493
The main problem is that you are taking those nodes into queue which are already having more than m consecutive cats in their path, the paths formed by them should never contribute to the answer.
Just put condition to check if number of consecutive cats till child node is less than or equal to m or not, then add that node to the queue.
Corrected Code