I can't understand problem exactly.
Problem says, for p=3 the infinite sequence is 1,2,4,5,10,11,13,14...
Why is "1,2,4,5,7,8,10,11..." sequence not allowed?
I think that this sequence doesn't contain arithmetic sequence length p.
I need help.
I use operator overloading calculating matrix.
And I divide equation like this.
A^1+A^2+...A^(2k) = A+A^2+...A^k + A^k(A+A^2..._A^k)
It throws me TLE.
What can I do to cut running time?
My method similar to you.
I also sort temperature and connect.
this means, If start and end point are same group(exist path),
then I try dijkstra algorithm.
I also connect every same temperature.
but I don't know why I got WA. plz help~~
I use union-set finding temperature and dijkstra finding length. I use these algorithms many times at other problems. But I only get WA in this problem. I already correct answer all of input at board What's the matter?