#P5582. 「SWTR-1」Escape
「SWTR-1」Escape
Description
After waking up, found himself standing in a strange place.
This place has platforms, forming a ring.
At this moment, 's voice sounded:
"Ha ha ha ha ha, congratulations. You are the first person to come to the Land of Death."
"As you can see, this place has platforms, and you are now standing on platform ."
"The remaining platforms are numbered clockwise as . That is, the platform behind you is platform ."
"Each time, you can jump clockwise by platforms, where , and may be different each time."
"If you can visit all platforms (the initial position does not count), then you can escape from the Land of Death."
(Here, the initial position does not count as visited; you need to visit platform again.)
"However, that is too easy. I will give you some numbers , meaning you cannot jump clockwise by platforms in one move."
"Also, you must complete my task using the minimum number of jumps."
"If you cannot satisfy the above two requirements, all platforms will disappear, and you will fall into the lava below."
Now, wants to know whether it is possible for him to escape this place.
If not, output -1. Otherwise, output the minimum number of jumps he needs.
Because thinks the Land of Death is really interesting, he decided to play a few more times, multiple test cases.
Input Format
The first line contains a positive integer , which represents the number of test cases.
In the next lines, there are test cases in total:
Line contains two integers , where is the number of in this test case.
Line contains numbers, and the -th number is .
Output Format
Output lines. The -th line is the answer for the -th test case.
3
5 4
1 2 3 4
5 4
1 2 4 5
6 3
1 3 5
-1
5
-1
Hint
Sample Explanation
The first test case:
can only jump clockwise by platforms each time, so it is clearly impossible to complete the task.
The second test case:
can only jump clockwise by platforms each time, and he can do it in jumps.
Constraints and Notes
。
It is guaranteed that , and they are pairwise distinct.
Test point .
Test point .
Test point .
Test point .
Test point .
Test point .
The dream woke up……
Translated by ChatGPT 5
京公网安备 11011102002149号