#P4368. [Code+#4] 喵呜

[Code+#4] 喵呜

Description

There is a neat row of nn cherry trees along the roadside, each exactly of height hh. One day, a cute kitten happened to climb onto the trees to play, but she is a bit allergic to cherry blossoms, so she now wants to leave these cherry trees as soon as possible.

Specifically, the kitten is currently at height yy on the xx-th cherry tree. She can leave the cherry trees by using two types of jumps:

Light jump: Move aa trees to the left or right while decreasing the height by bb. That is, in one light jump, she can move from the starting point to height yby-b on the (x+a)(x+a)-th or (xa)(x-a)-th tree. Note that when the kitten’s current height is not greater than bb, a light jump cannot be used.

Strong jump: Move aa trees to the left or right while increasing the height by bb. That is, in one strong jump, she can move from the starting point to height y+by+b on the (x+a)(x+a)-th or (xa)(x-a)-th tree. Note that when the kitten’s current height is greater than hbh-b, a strong jump cannot be used.

To leave this stretch of cherry trees, the kitten needs to move to either the 11-st or the nn-th tree, at height hh or 11 (so that she can breathe fresh air or just walk away from the trees). Now she wants to know the minimum number of jumps required to achieve the goal. Since she is a cute kitten, she hopes you will tell her.

Input Format

Read from standard input.

The first line contains a positive integer TT, the number of groups of testdata. There are no blank lines between groups.

Then follow TT lines, each describing one group of data:

Each group consists of one line containing six positive integers n,h,x,y,a,bn,h,x,y,a,b, whose meanings are as described in the problem statement.

Output Format

Output to standard output.

The output consists of TT groups of results, with no blank lines between groups. For each group of data:

If the kitten can successfully leave the cherry trees, output the minimum number of jumps she needs.

If the kitten cannot leave the cherry trees using the given jump methods, please output -1.

3
5 5 3 3 2 2
5 7 3 5 2 2
5 7 4 6 1 1
1
1
1
3
5 5 3 3 3 2
5 7 1 4 2 2
5 7 1 2 1 2
-1
-1
-1
4
999999999999 999999999999 454545454545 454545454545 1 1
777777777777 777777777777 343434343434 343434343434 1 1
777777777777 999999999999 343434343434 454545454545 1 1
999999999999 777777777777 454545454545 343434343434 1 1
454545454544
343434343433
-1
-1

Hint

Test point ID Range of n,hn,h Special note
1,21,2 10\le 10 b=1b=1
3,43,4 a=b=1a=b=1
5,6,7,85,6,7,8 None
9,109,10 500\le 500 b=1b=1
11,1211,12 a=b=1a=b=1
13,14,1513,14,15 None
16,1716,17 105\le 10^5 h10h \le 10
18,19,2018,19,20 None
21,2221,22 1015\le 10^{15} h10h \le 10
23,24,2523,24,25 None

For all testdata, it is guaranteed that n2n \ge 2, a<na < n, bhb \le h.

Credit: https://www.luogu.org/discuss/show/38908

Translated by ChatGPT 5